vms/run.py: refactor use kwargs instead of dataclass for function args
This commit is contained in:
parent
30db1039d1
commit
fc73301ed9
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -26,3 +26,4 @@ htmlcov
|
||||||
build
|
build
|
||||||
build-dir
|
build-dir
|
||||||
repo
|
repo
|
||||||
|
.env
|
||||||
|
|
|
@ -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__))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user