1
0
forked from clan/clan-core

Merge pull request 'clan machines list: reduce noise' (#1418) from a-kenji-fix/output-noisy/1115 into main

This commit is contained in:
clan-bot 2024-05-24 10:58:13 +00:00
commit 8055c21984
2 changed files with 12 additions and 5 deletions

View File

@ -39,7 +39,7 @@ def inspect_flake(flake_url: str | Path, machine_name: str) -> FlakeConfig:
system = config["system"]
# Check if the machine exists
machines = list_machines(flake_url)
machines = list_machines(False, flake_url)
if machine_name not in machines:
raise ClanError(
f"Machine {machine_name} not found in {flake_url}. Available machines: {', '.join(machines)}"

View File

@ -5,14 +5,17 @@ from pathlib import Path
from clan_cli.api import API
from ..cmd import run
from ..cmd import Log, run
from ..nix import nix_config, nix_eval
log = logging.getLogger(__name__)
@API.register
def list_machines(flake_url: Path | str) -> list[str]:
def list_machines(
debug: bool,
flake_url: Path | str,
) -> list[str]:
config = nix_config()
system = config["system"]
cmd = nix_eval(
@ -23,14 +26,18 @@ def list_machines(flake_url: Path | str) -> list[str]:
"--json",
]
)
proc = run(cmd)
if not debug:
proc = run(cmd, log=Log.NONE)
else:
proc = run(cmd)
res = proc.stdout.strip()
return json.loads(res)
def list_command(args: argparse.Namespace) -> None:
for machine in list_machines(Path(args.flake)):
for machine in list_machines(args.debug, Path(args.flake)):
print(machine)