From 48d7d5f38c76dbbd0d9330920359ab508bbb180c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 8 Dec 2023 11:47:25 +0100 Subject: [PATCH] vms/run/inspect: also make it more type-safe nix will show proper error messages when it cannot find a flake. --- pkgs/clan-cli/clan_cli/vms/inspect.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/vms/inspect.py b/pkgs/clan-cli/clan_cli/vms/inspect.py index d41c3b85..e5dec4e3 100644 --- a/pkgs/clan-cli/clan_cli/vms/inspect.py +++ b/pkgs/clan-cli/clan_cli/vms/inspect.py @@ -32,12 +32,20 @@ async def inspect_vm(flake_url: str | Path, flake_attr: str) -> VmConfig: return VmConfig(flake_url=flake_url, flake_attr=flake_attr, **data) +@dataclass +class InspectOptions: + machine: str + flake: Path + + def inspect_command(args: argparse.Namespace) -> None: - if args.flake is None: - flake = Path.cwd() - else: - flake = Path(args.flake) - res = asyncio.run(inspect_vm(flake_url=flake, flake_attr=args.machine)) + inspect_options = InspectOptions( + machine=args.machine, + flake=args.flake or Path.cwd(), + ) + res = asyncio.run( + inspect_vm(flake_url=inspect_options.flake, flake_attr=inspect_options.machine) + ) print("Cores:", res.cores) print("Memory size:", res.memory_size) print("Graphics:", res.graphics)