From ab2defa9e43c7e71eb1fe27c3a0cb3ac704b9263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 6 Mar 2024 11:27:26 +0100 Subject: [PATCH] add confirmation prompt when installing --- checks/installation/flake-module.nix | 2 +- pkgs/clan-cli/clan_cli/machines/install.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/checks/installation/flake-module.nix b/checks/installation/flake-module.nix index 0768ad4f..75ba9997 100644 --- a/checks/installation/flake-module.nix +++ b/checks/installation/flake-module.nix @@ -107,7 +107,7 @@ in client.succeed("${pkgs.coreutils}/bin/install -Dm 600 ${../lib/ssh/privkey} /root/.ssh/id_ed25519") client.wait_until_succeeds("ssh -o StrictHostKeyChecking=accept-new -v root@target hostname") - client.succeed("clan --debug --flake ${../..} machines install test_install_machine root@target >&2") + client.succeed("clan --debug --flake ${../..} machines install --yes test_install_machine root@target >&2") try: target.shutdown() except BrokenPipeError: diff --git a/pkgs/clan-cli/clan_cli/machines/install.py b/pkgs/clan-cli/clan_cli/machines/install.py index 701303fe..82566adf 100644 --- a/pkgs/clan-cli/clan_cli/machines/install.py +++ b/pkgs/clan-cli/clan_cli/machines/install.py @@ -63,6 +63,7 @@ class InstallOptions: machine: str target_host: str kexec: str | None + confirm: bool def install_command(args: argparse.Namespace) -> None: @@ -71,10 +72,16 @@ def install_command(args: argparse.Namespace) -> None: machine=args.machine, target_host=args.target_host, kexec=args.kexec, + confirm=not args.yes, ) machine = Machine(opts.machine, flake=opts.flake) machine.target_host_address = opts.target_host + if opts.confirm: + ask = input(f"Install {machine.name} to {opts.target_host}? [y/N] ") + if ask != "y": + return + install_nixos(machine, kexec=opts.kexec) @@ -84,6 +91,12 @@ def register_install_parser(parser: argparse.ArgumentParser) -> None: type=str, help="use another kexec tarball to bootstrap NixOS", ) + parser.add_argument( + "--yes", + action="store_true", + help="do not ask for confirmation", + default=False, + ) parser.add_argument( "machine", type=str,