clan machines list: reduce noise
Don't log nix error output by default on `clan machines list`. Log it, if `--debug` is passed. Fixes #1115
This commit is contained in:
@@ -39,7 +39,7 @@ def inspect_flake(flake_url: str | Path, machine_name: str) -> FlakeConfig:
|
|||||||
system = config["system"]
|
system = config["system"]
|
||||||
|
|
||||||
# Check if the machine exists
|
# Check if the machine exists
|
||||||
machines = list_machines(flake_url)
|
machines = list_machines(False, flake_url)
|
||||||
if machine_name not in machines:
|
if machine_name not in machines:
|
||||||
raise ClanError(
|
raise ClanError(
|
||||||
f"Machine {machine_name} not found in {flake_url}. Available machines: {', '.join(machines)}"
|
f"Machine {machine_name} not found in {flake_url}. Available machines: {', '.join(machines)}"
|
||||||
|
|||||||
@@ -5,14 +5,17 @@ from pathlib import Path
|
|||||||
|
|
||||||
from clan_cli.api import API
|
from clan_cli.api import API
|
||||||
|
|
||||||
from ..cmd import run
|
from ..cmd import Log, run
|
||||||
from ..nix import nix_config, nix_eval
|
from ..nix import nix_config, nix_eval
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@API.register
|
@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()
|
config = nix_config()
|
||||||
system = config["system"]
|
system = config["system"]
|
||||||
cmd = nix_eval(
|
cmd = nix_eval(
|
||||||
@@ -23,14 +26,18 @@ def list_machines(flake_url: Path | str) -> list[str]:
|
|||||||
"--json",
|
"--json",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
proc = run(cmd)
|
|
||||||
|
if not debug:
|
||||||
|
proc = run(cmd, log=Log.NONE)
|
||||||
|
else:
|
||||||
|
proc = run(cmd)
|
||||||
|
|
||||||
res = proc.stdout.strip()
|
res = proc.stdout.strip()
|
||||||
return json.loads(res)
|
return json.loads(res)
|
||||||
|
|
||||||
|
|
||||||
def list_command(args: argparse.Namespace) -> None:
|
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)
|
print(machine)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user