diff options
author | Martin Czygan <martin.czygan@gmail.com> | 2021-06-08 21:35:24 +0200 |
---|---|---|
committer | Martin Czygan <martin.czygan@gmail.com> | 2021-06-08 21:35:24 +0200 |
commit | f43001328eb51009d86f6d2736650a90ba408afa (patch) | |
tree | 724f73d6b3d5d6455995c7c99cda840d4314b378 /python | |
parent | 2051913b491e06104915f66ef5df519cf66d3a25 (diff) | |
download | refcat-f43001328eb51009d86f6d2736650a90ba408afa.tar.gz refcat-f43001328eb51009d86f6d2736650a90ba408afa.zip |
cli: error handling
Diffstat (limited to 'python')
-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(): |