Templates/list: display templates via exposed nix value
This commit is contained in:
@@ -7,17 +7,38 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def list_command(args: argparse.Namespace) -> None:
|
||||
template_list = list_templates("clan", args.flake)
|
||||
templates = list_templates(args.flake)
|
||||
|
||||
print("Available local templates:")
|
||||
for name, template in template_list.self.items():
|
||||
print(f" {name}: {template['description']}")
|
||||
builtin_clan_templates = templates.builtins.get("clan", {})
|
||||
|
||||
print("Available templates from inputs:")
|
||||
for input_name, input_templates in template_list.inputs.items():
|
||||
print(f" {input_name}:")
|
||||
for name, template in input_templates.items():
|
||||
print(f" {name}: {template['description']}")
|
||||
print("Available templates")
|
||||
print("├── <builtin>")
|
||||
for i, (name, template) in enumerate(builtin_clan_templates.items()):
|
||||
is_last_template = i == len(builtin_clan_templates.items()) - 1
|
||||
if not is_last_template:
|
||||
print(f"│ ├── {name}: {template.get('description', 'no description')}")
|
||||
else:
|
||||
print(f"│ └── {name}: {template.get('description', 'no description')}")
|
||||
|
||||
for i, (input_name, input_templates) in enumerate(templates.custom.items()):
|
||||
custom_clan_templates = input_templates.get("clan", {})
|
||||
is_last_input = i == len(templates.custom.items()) - 1
|
||||
prefix = "│" if not is_last_input else " "
|
||||
if not is_last_input:
|
||||
print(f"├── inputs.{input_name}:")
|
||||
else:
|
||||
print(f"└── inputs.{input_name}:")
|
||||
|
||||
for i, (name, template) in enumerate(custom_clan_templates.items()):
|
||||
is_last_template = i == len(builtin_clan_templates.items()) - 1
|
||||
if not is_last_template:
|
||||
print(
|
||||
f"{prefix} ├── {name}: {template.get('description', 'no description')}"
|
||||
)
|
||||
else:
|
||||
print(
|
||||
f"{prefix} └── {name}: {template.get('description', 'no description')}"
|
||||
)
|
||||
|
||||
|
||||
def register_list_parser(parser: argparse.ArgumentParser) -> None:
|
||||
|
||||
@@ -17,7 +17,6 @@ from clan_lib.templates import (
|
||||
TemplateName,
|
||||
get_clan_nix_attrset,
|
||||
get_template,
|
||||
list_templates,
|
||||
)
|
||||
from clan_lib.templates.filesystem import copy_from_nixstore
|
||||
|
||||
@@ -96,10 +95,6 @@ def test_clan_core_templates(
|
||||
expected_templates = ["default", "flake-parts", "minimal", "minimal-flake-parts"]
|
||||
assert clan_core_template_keys == expected_templates
|
||||
|
||||
vlist_temps = list_templates("clan", clan_dir)
|
||||
list_template_keys = list(vlist_temps.inputs[InputName("clan-core")].keys())
|
||||
assert list_template_keys == expected_templates
|
||||
|
||||
default_template = get_template(
|
||||
TemplateName("default"),
|
||||
"clan",
|
||||
|
||||
Reference in New Issue
Block a user