diff --git a/src/infra_rebuild/cli/__init__.py b/src/infra_rebuild/cli/__init__.py index 05cef25..38030ea 100644 --- a/src/infra_rebuild/cli/__init__.py +++ b/src/infra_rebuild/cli/__init__.py @@ -2,8 +2,6 @@ import click from infra_rebuild import operations -reboot_option_help_text = "Reboot the target hosts after running the operation." - @click.group(context_settings={"help_option_names": ["-h", "--help"]}, invoke_without_command=True) @click.version_option(prog_name="infra-rebuild") @@ -30,27 +28,24 @@ def build_vm_with_bootloader(hosts): @infra_rebuild.command() -@click.option("--reboot", is_flag=True, help=reboot_option_help_text) @click.argument("hosts", nargs=-1) -def switch(hosts, reboot): - operations.run("switch", hosts, reboot) +def switch(hosts): + operations.run("switch", hosts) @infra_rebuild.command() -@click.option("--reboot", is_flag=True, help=reboot_option_help_text) @click.argument("hosts", nargs=-1) -def boot(hosts, reboot): - operations.run("boot", hosts, reboot) +def boot(hosts): + operations.run("boot", hosts) @infra_rebuild.command() -@click.option("--reboot", is_flag=True, help=reboot_option_help_text) @click.argument("hosts", nargs=-1) -def test(hosts, reboot): - operations.run("test", hosts, reboot) +def test(hosts): + operations.run("test", hosts) -@infra_rebuild.command(short_help=" ", help="This operation is a convenience alias for boot --reboot.") +@infra_rebuild.command() @click.argument("hosts", nargs=-1) def reboot(hosts): - operations.run("boot", hosts, True) + operations.run("reboot", hosts) diff --git a/src/infra_rebuild/operations/__init__.py b/src/infra_rebuild/operations/__init__.py index b8d3f28..0ae726e 100644 --- a/src/infra_rebuild/operations/__init__.py +++ b/src/infra_rebuild/operations/__init__.py @@ -6,12 +6,19 @@ import sys from infra_rebuild import msg -def run(operation, hosts, reboot=False): # noqa: FBT002 - having reboot as a Boolean positional argument is fine I think # fmt: skip +def run(operation, hosts): + act_remotely = False + reboot = False match operation: case "build" | "build-vm" | "build-vm-with-bootloader": - act_remotely = False + actual_operation = operation case "switch" | "boot" | "test": act_remotely = True + actual_operation = operation + case "reboot": + act_remotely = True + actual_operation = "boot" + reboot = True case _: msg.error("Internal Error: The given operation isn't valid.") sys.exit(1) @@ -22,9 +29,9 @@ def run(operation, hosts, reboot=False): # noqa: FBT002 - having reboot as a Bo continue if act_remotely: - remote(operation, host, reboot) + remote(actual_operation, host, reboot) else: - local(operation, host) + local(actual_operation, host) def local(operation, host):