From 86536bae42789dfd87c8dc287253cf7559f4e6d8 Mon Sep 17 00:00:00 2001 From: Qubasa Date: Tue, 17 Jun 2025 12:59:53 +0200 Subject: [PATCH] clan-lib: Refactor remote host handling to function parameters This refactoring improves the separation of concerns by moving remote host creation logic from the Machine class to the calling functions, making the code more flexible and testable. --- pkgs/clan-cli/clan_cli/machines/install.py | 4 +--- pkgs/clan-cli/clan_cli/machines/update.py | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/machines/install.py b/pkgs/clan-cli/clan_cli/machines/install.py index 6e5c5afed..0196b7378 100644 --- a/pkgs/clan-cli/clan_cli/machines/install.py +++ b/pkgs/clan-cli/clan_cli/machines/install.py @@ -205,9 +205,7 @@ def install_command(args: argparse.Namespace) -> None: raise ClanError(msg) if not args.yes: - ask = input( - f"Install {args.machine} to {machine.target_host().target}? [y/N] " - ) + ask = input(f"Install {args.machine} to {target_host.target}? [y/N] ") if ask != "y": return None diff --git a/pkgs/clan-cli/clan_cli/machines/update.py b/pkgs/clan-cli/clan_cli/machines/update.py index 19f9e126e..d8d80f198 100644 --- a/pkgs/clan-cli/clan_cli/machines/update.py +++ b/pkgs/clan-cli/clan_cli/machines/update.py @@ -212,10 +212,6 @@ def update_command(args: argparse.Namespace) -> None: args.machines if args.machines else list_full_machines(args.flake).keys() ) - if args.target_host is not None and len(args.machines) > 1: - msg = "Target Host can only be set for one machines" - raise ClanError(msg) - for machine_name in selected_machines: machine = Machine( name=machine_name, @@ -225,6 +221,10 @@ def update_command(args: argparse.Namespace) -> None: ) machines.append(machine) + if args.target_host is not None and len(machines) > 1: + msg = "Target Host can only be set for one machines" + raise ClanError(msg) + def filter_machine(m: Machine) -> bool: if m.deployment.get("requireExplicitUpdate", False): return False