Merge pull request 'make cli options more type safe using a dataclass' (#619) from Mic92-main into main
All checks were successful
assets1 / test (push) Successful in 19s
checks-impure / test (push) Successful in 1m13s
checks / test (push) Successful in 1m58s

This commit is contained in:
clan-bot 2023-12-08 10:33:44 +00:00
commit 72327093c2

View File

@ -7,6 +7,7 @@ import shlex
import subprocess
import sys
import tempfile
from dataclasses import dataclass, field
from pathlib import Path
from typing import IO
@ -268,13 +269,23 @@ def run_vm(
raise ClanError(f"qemu failed with {res.returncode}")
@dataclass
class RunOptions:
machine: str
flake_url: str | None
nix_options: list[str] = field(default_factory=list)
flake: Path | None = None
def run_command(args: argparse.Namespace) -> None:
flake_url = args.flake_url or args.flake
run_options = RunOptions(args.machine, args.flake_url, args.option, args.flake)
flake_url = run_options.flake_url or run_options.flake
if not flake_url:
flake_url = Path.cwd()
vm = asyncio.run(inspect_vm(flake_url=flake_url, flake_attr=args.machine))
vm = asyncio.run(inspect_vm(flake_url=flake_url, flake_attr=run_options.machine))
run_vm(vm, args.option)
run_vm(vm, run_options.nix_options)
def register_run_parser(parser: argparse.ArgumentParser) -> None: