forked from clan/clan-core
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-dir
|
||||
repo
|
||||
.env
|
||||
|
@ -4,7 +4,6 @@ import json
|
||||
import logging
|
||||
import os
|
||||
from contextlib import ExitStack
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
@ -192,28 +191,19 @@ def run_vm(
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class RunOptions:
|
||||
machine: str
|
||||
flake: Path
|
||||
nix_options: list[str] = field(default_factory=list)
|
||||
waypipe: bool = False
|
||||
def run_command(
|
||||
machine: str,
|
||||
flake: Path,
|
||||
option: list[str] = [],
|
||||
**kwargs: dict[str, str],
|
||||
) -> None:
|
||||
machine_obj: Machine = Machine(machine, flake)
|
||||
|
||||
vm: VmConfig = inspect_vm(machine=machine_obj)
|
||||
|
||||
def run_command(args: argparse.Namespace) -> None:
|
||||
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)
|
||||
run_vm(vm, nix_options=option)
|
||||
|
||||
|
||||
def register_run_parser(parser: argparse.ArgumentParser) -> None:
|
||||
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