diff options
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. |