api/tags: split list into options and non-configurable tags

This commit is contained in:
Johannes Kirschbauer
2025-08-12 12:40:12 +02:00
parent cbd3b08296
commit a9d1ff83f2
2 changed files with 26 additions and 10 deletions

View File

@@ -1,3 +1,4 @@
from dataclasses import dataclass
from typing import Any
from clan_lib.api import API
@@ -5,8 +6,14 @@ from clan_lib.flake import Flake
from clan_lib.persist.inventory_store import InventoryStore
@dataclass
class TagList:
options: set[str]
special: set[str]
@API.register
def list_tags(flake: Flake) -> set[str]:
def list_tags(flake: Flake) -> TagList:
inventory_store = InventoryStore(flake=flake)
inventory = inventory_store.read()
@@ -28,7 +35,11 @@ def list_tags(flake: Flake) -> set[str]:
tags.add(tag)
global_tags = inventory.get("tags", {})
for tag in global_tags:
tags.add(tag)
return tags
for tag in global_tags:
if tag not in tags:
continue
tags.remove(tag)
return TagList(options=tags, special=set(global_tags.keys()))

View File

@@ -55,13 +55,8 @@ def test_list_inventory_tags(clan_flake: Callable[..., Flake]) -> None:
tags = list_tags(flake)
assert tags == set(
assert tags.options == set(
{
# Predefined tags
"all",
"global",
"darwin",
"nixos",
# Tags defined in nix
"bar",
"baz",
@@ -76,3 +71,13 @@ def test_list_inventory_tags(clan_flake: Callable[..., Flake]) -> None:
"managed2",
}
)
assert tags.special == set(
{
# Predefined tags
"all",
"global",
"darwin",
"nixos",
}
)