vms/run.py: refactor use kwargs instead of dataclass for function args
All checks were successful
checks / check-links (pull_request) Successful in 14s
checks / checks-impure (pull_request) Successful in 1m54s
checks / checks (pull_request) Successful in 4m10s

This commit is contained in:
DavHau 2024-04-09 13:30:40 +07:00
parent 30db1039d1
commit fc73301ed9
2 changed files with 11 additions and 20 deletions

1
.gitignore vendored
View File

@ -26,3 +26,4 @@ htmlcov
build build
build-dir build-dir
repo repo
.env

View File

@ -4,7 +4,6 @@ import json
import logging import logging
import os import os
from contextlib import ExitStack from contextlib import ExitStack
from dataclasses import dataclass, field
from pathlib import Path from pathlib import Path
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
@ -192,28 +191,19 @@ def run_vm(
) )
@dataclass def run_command(
class RunOptions: machine: str,
machine: str flake: Path,
flake: Path option: list[str] = [],
nix_options: list[str] = field(default_factory=list) **kwargs: dict[str, str],
waypipe: bool = False ) -> None:
machine_obj: Machine = Machine(machine, flake)
vm: VmConfig = inspect_vm(machine=machine_obj)
def run_command(args: argparse.Namespace) -> None: run_vm(vm, nix_options=option)
run_options = RunOptions(
machine=args.machine,
flake=args.flake,
nix_options=args.option,
)
machine = Machine(run_options.machine, run_options.flake)
vm = inspect_vm(machine=machine)
run_vm(vm, nix_options=run_options.nix_options)
def register_run_parser(parser: argparse.ArgumentParser) -> None: def register_run_parser(parser: argparse.ArgumentParser) -> None:
parser.add_argument("machine", type=str, help="machine in the flake to run") parser.add_argument("machine", type=str, help="machine in the flake to run")
parser.set_defaults(func=run_command) parser.set_defaults(func=lambda args: run_command(**args.__dict__))