pkgs/cli: Add tagging support to machines list

Add the `--tags` flag to `clan machines list`
This now supports the machine tagging system from the inventory.

Multiple tags are the intersection of the tags of a specific machine.

Example two machines with overlapping tags:
```
server: ["intel"]
laptop: ["intel", "graphical"]
```

- `clan machines list --tags intel` will output:

```
server
laptop
```

- `clan machines list --tags intel graphical` will output:

```
laptop
```

- `clan machines list --tags graphical` will output:

```
laptop
```
This commit is contained in:
a-kenji
2024-11-12 14:57:06 +01:00
parent 642cb434c2
commit 8a6239e08d
2 changed files with 68 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ from clan_cli.cmd import run_no_stdout
from clan_cli.errors import ClanCmdError, ClanError
from clan_cli.inventory import Machine, load_inventory_eval, set_inventory
from clan_cli.nix import nix_eval, nix_shell
from clan_cli.tags import list_nixos_machines_by_tags
log = logging.getLogger(__name__)
@@ -132,9 +133,18 @@ def check_machine_online(
def list_command(args: argparse.Namespace) -> None:
flake_path = args.flake.path
if args.tags:
list_nixos_machines_by_tags(flake_path, args.tags)
return
for name in list_nixos_machines(flake_path):
print(name)
def register_list_parser(parser: argparse.ArgumentParser) -> None:
tag_parser = parser.add_argument(
"--tags",
nargs="+",
default=[],
help="Tags that machines should be queried for. Multiple tags will intersect.",
)
parser.set_defaults(func=list_command)