diff options
-rw-r--r-- | python/refcat/cli.py | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/python/refcat/cli.py b/python/refcat/cli.py index 7e3804c..61b44b9 100644 --- a/python/refcat/cli.py +++ b/python/refcat/cli.py @@ -95,9 +95,9 @@ def cat(): """ if len(sys.argv) < 2: raise ValueError("task name required") - parser = CmdlineParser(sys.argv[2:]) - output = parser.get_task_obj().output() try: + parser = CmdlineParser(sys.argv[2:]) + output = parser.get_task_obj().output() filename = output.path if filename.endswith(".zst"): subprocess.run(["zstdcat", "-T0", filename]) @@ -109,6 +109,8 @@ def cat(): print("file not found: {}".format(filename), file=sys.stderr) except AttributeError: print("most likely not a task object", file=sys.stderr) + except TaskClassNotFoundException as exc: + print("no such task") def ls(): @@ -117,9 +119,13 @@ def ls(): """ if len(sys.argv) < 2: raise ValueError("task name required") - parser = CmdlineParser(sys.argv[2:]) - output = parser.get_task_obj().output() - print(output.path) + try: + parser = CmdlineParser(sys.argv[2:]) + output = parser.get_task_obj().output() + except TaskClassNotFoundException as exc: + print("no such task") + else: + print(output.path) def ll(): @@ -128,16 +134,17 @@ def ll(): """ if len(sys.argv) < 2: raise ValueError("task name required") - parser = CmdlineParser(sys.argv[2:]) - output = parser.get_task_obj().output() try: + parser = CmdlineParser(sys.argv[2:]) + output = parser.get_task_obj().output() filename = output.path subprocess.run(["ls", "-lah", filename]) except FileNotFoundError: print("file not found: {}".format(filename), file=sys.stderr) except AttributeError: print("most likely not a task object", file=sys.stderr) - + except TaskClassNotFoundException as exc: + print("no such task") def deps(): """ @@ -145,9 +152,12 @@ def deps(): """ if len(sys.argv) < 2: raise ValueError("task name required") - parser = CmdlineParser(sys.argv[2:]) - obj = parser.get_task_obj() - dump_deps(obj) + try: + parser = CmdlineParser(sys.argv[2:]) + obj = parser.get_task_obj() + dump_deps(obj) + except TaskClassNotFoundException as exc: + print("no such task") def config(): |