Compare commits

...

2 commits

Author SHA1 Message Date
June d164f502a1
docs: add help text doc. that reboot is a conv. alias for boot --reboot
All checks were successful
/ ruff (push) Successful in 26s
/ black (push) Successful in 26s
2024-06-09 00:33:24 +02:00
June fd9ad17d79
feature: add --reboot flag for remote operations (except for "reboot")
All checks were successful
/ ruff (push) Successful in 25s
/ black (push) Successful in 26s
Also make the "reboot" operation basically an alias for "boot --reboot"
then and simplify the code of the operations.run function, since it
doesn't need to convert between operation and actual_operation anymore.
2024-06-09 00:26:04 +02:00
2 changed files with 17 additions and 19 deletions

View file

@ -2,6 +2,8 @@ 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")
@ -28,24 +30,27 @@ 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):
operations.run("switch", hosts)
def switch(hosts, reboot):
operations.run("switch", hosts, reboot)
@infra_rebuild.command()
@click.option("--reboot", is_flag=True, help=reboot_option_help_text)
@click.argument("hosts", nargs=-1)
def boot(hosts):
operations.run("boot", hosts)
def boot(hosts, reboot):
operations.run("boot", hosts, reboot)
@infra_rebuild.command()
@click.option("--reboot", is_flag=True, help=reboot_option_help_text)
@click.argument("hosts", nargs=-1)
def test(hosts):
operations.run("test", hosts)
def test(hosts, reboot):
operations.run("test", hosts, reboot)
@infra_rebuild.command()
@infra_rebuild.command(short_help=" ", help="This operation is a convenience alias for boot --reboot.")
@click.argument("hosts", nargs=-1)
def reboot(hosts):
operations.run("reboot", hosts)
operations.run("boot", hosts, True)

View file

@ -6,19 +6,12 @@ import sys
from infra_rebuild import msg
def run(operation, hosts):
act_remotely = False
reboot = False
def run(operation, hosts, reboot=False): # noqa: FBT002 - having reboot as a Boolean positional argument is fine I think # fmt: skip
match operation:
case "build" | "build-vm" | "build-vm-with-bootloader":
actual_operation = operation
act_remotely = False
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)
@ -29,9 +22,9 @@ def run(operation, hosts):
continue
if act_remotely:
remote(actual_operation, host, reboot)
remote(operation, host, reboot)
else:
local(actual_operation, host)
local(operation, host)
def local(operation, host):