feat: add default option

This commit is contained in:
Daylin Morgan 2024-10-22 13:26:17 -05:00
parent d8a2dc6884
commit 563d9dc927
Signed by: daylin
GPG key ID: 950D13E9719334AD

View file

@ -135,9 +135,6 @@ class Context:
for task in self._tasks.values(): for task in self._tasks.values():
if not task.targets: if not task.targets:
continue continue
print(task.name)
print(task.targets)
print(task.needs)
for target in task.targets: for target in task.targets:
if not task.needs: if not task.needs:
self._graph.add_nodes(task, target, None) self._graph.add_nodes(task, target, None)
@ -676,7 +673,7 @@ def _task_repr(func: Callable) -> str:
) )
def cli() -> None: def cli(default: str | None = None) -> None:
ctx._generate_graph() ctx._generate_graph()
parser = ArgumentParser( parser = ArgumentParser(
@ -708,11 +705,14 @@ def cli() -> None:
for task in ctx._tasks.values(): for task in ctx._tasks.values():
_generate_task_subparser(shared, subparsers, task) _generate_task_subparser(shared, subparsers, task)
# TODO: add support for default arg?
if len(sys.argv) == 1: if len(sys.argv) == 1:
parser.print_help(sys.stderr) if default:
sys.exit(1) sys.argv.append(default)
elif "--" in sys.argv: else:
parser.print_help(sys.stderr)
sys.exit(1)
if "--" in sys.argv:
i = sys.argv.index("--") i = sys.argv.index("--")
args = vars(parser.parse_args(sys.argv[1:i])) args = vars(parser.parse_args(sys.argv[1:i]))
ctx.rest = sys.argv[i + 1 :] ctx.rest = sys.argv[i + 1 :]