pkgs/cli: Validate clan flake for clan machines list

This commit is contained in:
a-kenji
2025-07-29 10:14:34 +02:00
parent a2404f5fbb
commit 86ac1c4405
2 changed files with 12 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
import argparse
import logging
from clan_lib.flake import Flake
from clan_lib.flake import require_flake
from clan_lib.machines.actions import list_machines
from clan_cli.completions import add_dynamic_completer, complete_tags
@@ -10,7 +10,7 @@ log = logging.getLogger(__name__)
def list_command(args: argparse.Namespace) -> None:
flake: Flake = args.flake
flake = require_flake(args.flake)
for name in list_machines(flake, opts={"filter": {"tags": args.tags}}):
print(name)

View File

@@ -1,4 +1,5 @@
import pytest
from clan_lib.errors import ClanError
from clan_cli.tests import fixtures_flakes
from clan_cli.tests.helpers import cli
@@ -359,3 +360,12 @@ def list_mixed_tagged_untagged(
assert "machine-with-tags" not in output.out
assert "machine-without-tags" not in output.out
assert output.out.strip() == ""
def test_machines_list_require_flake_error() -> None:
"""Test that machines list command fails when flake is required but not provided."""
with pytest.raises(ClanError) as exc_info:
cli.run(["machines", "list"])
error_message = str(exc_info.value)
assert "flake" in error_message.lower()