pkgs/clan/cli: Add clan flake validation to clan vars check
This now gives a clearer error than:
```
Traceback (most recent call last):
File "/nix/store/mznnb8il3njp6jxn5i57d0myjdh6cs0i-clan-cli/bin/.clan-wrapped", line 9, in <module>
sys.exit(main())
~~~~^^
File "/nix/store/mznnb8il3njp6jxn5i57d0myjdh6cs0i-clan-cli/lib/python3.13/site-packages/clan_cli/cli.py", line 516, in main
args.func(args)
~~~~~~~~~^^^^^^
File "/nix/store/mznnb8il3njp6jxn5i57d0myjdh6cs0i-clan-cli/lib/python3.13/site-packages/clan_cli/vars/check.py", line 113, in check_command
ok = check_vars(args.machine, args.flake, generator_name=args.generator)
File "/nix/store/mznnb8il3njp6jxn5i57d0myjdh6cs0i-clan-cli/lib/python3.13/site-packages/clan_cli/vars/check.py", line 103, in check_vars
status = vars_status(machine_name, flake, generator_name=generator_name)
File "/nix/store/mznnb8il3njp6jxn5i57d0myjdh6cs0i-clan-cli/lib/python3.13/site-packages/clan_cli/vars/check.py", line 41, in vars_status
generators = Generator.generators_from_flake(machine.name, machine.flake)
File "/nix/store/mznnb8il3njp6jxn5i57d0myjdh6cs0i-clan-cli/lib/python3.13/site-packages/clan_cli/vars/generate.py", line 67, in generators_from_flake
generators_data = flake.select_machine(
^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'select_machine'
```
When not being in a flake.
This commit is contained in:
@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from clan_cli.completions import add_dynamic_completer, complete_machines
|
||||
from clan_lib.errors import ClanError
|
||||
from clan_lib.flake import Flake
|
||||
from clan_lib.flake import Flake, require_flake
|
||||
from clan_lib.machines.machines import Machine
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -110,7 +110,8 @@ def check_vars(
|
||||
|
||||
|
||||
def check_command(args: argparse.Namespace) -> None:
|
||||
ok = check_vars(args.machine, args.flake, generator_name=args.generator)
|
||||
flake = require_flake(args.flake)
|
||||
ok = check_vars(args.machine, flake, generator_name=args.generator)
|
||||
if not ok:
|
||||
raise SystemExit(1)
|
||||
|
||||
|
||||
14
pkgs/clan-cli/clan_cli/vars/check_test.py
Normal file
14
pkgs/clan-cli/clan_cli/vars/check_test.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from clan_cli.tests.helpers import cli
|
||||
from clan_lib.errors import ClanError
|
||||
|
||||
|
||||
def test_check_command_no_flake(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
monkeypatch.chdir(tmp_path)
|
||||
|
||||
with pytest.raises(ClanError):
|
||||
cli.run(["vars", "check", "machine1"])
|
||||
Reference in New Issue
Block a user