diff options
author | Martin Czygan <martin.czygan@gmail.com> | 2021-06-08 21:13:30 +0200 |
---|---|---|
committer | Martin Czygan <martin.czygan@gmail.com> | 2021-06-08 21:13:30 +0200 |
commit | 9a959c22403f4c5aa111531c3c3b626dfbb97251 (patch) | |
tree | a5fc6895b2414c43a55763fa6e09b8adac0e12d8 /python | |
parent | 221a8ef05889d777ce36c4f8582ff6d62116ca2b (diff) | |
download | refcat-9a959c22403f4c5aa111531c3c3b626dfbb97251.tar.gz refcat-9a959c22403f4c5aa111531c3c3b626dfbb97251.zip |
cli: cleanup and simplify
Diffstat (limited to 'python')
-rw-r--r-- | python/refcat/cli.py | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/python/refcat/cli.py b/python/refcat/cli.py index 2aff453..5d62918 100644 --- a/python/refcat/cli.py +++ b/python/refcat/cli.py @@ -60,12 +60,20 @@ suppress_task_names = [ ] +def effective_task_names(): + """ + Runnable, relevant task names. + """ + names = (name for name in sorted(Register.task_names())) + names = (name for name in names if name not in suppress_task_names and not name.islower()) + return names + + def tasks(): """ Print task name. """ - names = [name for name in sorted(Register.task_names()) if name not in suppress_task_names and not name.islower()] - for name in names: + for name in effective_task_names(): print(name) @@ -73,8 +81,7 @@ def files(): """ Print task name and file. """ - names = [name for name in sorted(Register.task_names()) if name not in suppress_task_names and not name.islower()] - for name in names: + for name in effective_task_names(): klass = Register.get_task_cls(name) try: print("{:40s}{}".format(name, klass().output().path)) @@ -86,8 +93,8 @@ def cat(*args): """ Inspect file. """ - if len(args) == 0: - raise ValueError("ls failed: task name required") + if len(sys.argv) < 2: + raise ValueError("task name required") parser = CmdlineParser(sys.argv[2:]) output = parser.get_task_obj().output() try: @@ -104,23 +111,23 @@ def cat(*args): print("most likely not a task object", file=sys.stderr) -def ls(*args): +def ls(): """ Print output filename for task. """ - if len(args) == 0: - raise ValueError("ls failed: task name required") + if len(sys.argv) < 2: + raise ValueError("task name required") parser = CmdlineParser(sys.argv[2:]) output = parser.get_task_obj().output() print(output.path) -def ll(*args): +def ll(): """ Long output. """ - if len(args) == 0: - raise ValueError("ls failed: task name required") + if len(sys.argv) < 2: + raise ValueError("task name required") parser = CmdlineParser(sys.argv[2:]) output = parser.get_task_obj().output() try: @@ -132,12 +139,12 @@ def ll(*args): print("most likely not a task object", file=sys.stderr) -def deps(*args): +def deps(): """ Render task dependencies. """ - if len(args) == 0: - raise ValueError("deps failed: task name required") + if len(sys.argv) < 2: + raise ValueError("task name required") parser = CmdlineParser(sys.argv[2:]) obj = parser.get_task_obj() dump_deps(obj) @@ -186,18 +193,6 @@ complete -F _refcat_completion "refcat" print(snippet) -def find_task_class(name): - """ - Note: return task class, not instance. - """ - task_class = globals().get(name) - if task_class is None: - raise RuntimeError("no such task: {}".format(name)) - if not isinstance(task_class(), luigi.Task): - raise RuntimeError("not a task: {}".format(name)) - return task_class - - def main(): """ The main command line entry point. |