pw_cli: Use an absolute path for -C
The -C/--directory path needs to be resolved before changing the
directory with os.chdir, otherwise it may not resolve correctly.
Change-Id: If8c26c17957e27dfbc35d9acd5b07d93ed928b36
diff --git a/pw_cli/py/pw_cli/__main__.py b/pw_cli/py/pw_cli/__main__.py
index c82500c..096f341 100644
--- a/pw_cli/py/pw_cli/__main__.py
+++ b/pw_cli/py/pw_cli/__main__.py
@@ -36,7 +36,7 @@
if not args.no_banner:
arguments.print_banner()
- _LOG.debug('Executing the pw command from %s', args.directory.resolve())
+ _LOG.debug('Executing the pw command from %s', args.directory)
os.chdir(args.directory)
plugins.register(args.directory)
diff --git a/pw_cli/py/pw_cli/arguments.py b/pw_cli/py/pw_cli/arguments.py
index 5e37823..baac649 100644
--- a/pw_cli/py/pw_cli/arguments.py
+++ b/pw_cli/py/pw_cli/arguments.py
@@ -70,11 +70,10 @@
def directory(arg: str) -> Path:
path = Path(arg)
- if not path.is_dir():
- raise argparse.ArgumentTypeError(
- f'{path} is not a path to a directory')
+ if path.is_dir():
+ return path.resolve()
- return path
+ raise argparse.ArgumentTypeError(f'{path} is not a directory')
def log_level(arg: str) -> int:
try: