pkgs/cli: Add completions to clan flakes create --template [TEMPLATE]

Add completions to `clan flakes create --template [TEMPLATE]`
This commit is contained in:
a-kenji
2025-07-22 13:01:45 +02:00
parent 77f75b916d
commit fb52b955cc
2 changed files with 24 additions and 1 deletions

View File

@@ -6,11 +6,13 @@ from pathlib import Path
from clan_lib.clan.create import CreateOptions, create_clan
from clan_lib.errors import ClanError
from clan_cli.completions import add_dynamic_completer, complete_templates_clan
log = logging.getLogger(__name__)
def register_create_parser(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
template_action = parser.add_argument(
"--template",
type=str,
help="""Reference to the template to use for the clan. default="default". In the format '<flake_ref>#template_name' Where <flake_ref> is a flake reference (e.g. github:org/repo) or a local path (e.g. '.' ).
@@ -18,6 +20,7 @@ def register_create_parser(parser: argparse.ArgumentParser) -> None:
""",
default="default",
)
add_dynamic_completer(template_action, complete_templates_clan)
parser.add_argument(
"--no-git",

View File

@@ -269,6 +269,26 @@ def complete_templates_disko(
return []
def complete_templates_clan(
prefix: str, parsed_args: argparse.Namespace, **kwargs: Any
) -> Iterable[str]:
"""
Provides completion functionality for clan templates
"""
from clan_lib.templates import list_templates
flake = clan_dir_result if (clan_dir_result := clan_dir(None)) is not None else "."
list_all_templates = list_templates(Flake(flake))
clan_template_list = list_all_templates.builtins.get("clan")
if clan_template_list:
clan_templates = list(clan_template_list)
clan_dict = dict.fromkeys(clan_templates, "clan")
return clan_dict
return []
def complete_target_host(
prefix: str, parsed_args: argparse.Namespace, **kwargs: Any
) -> Iterable[str]: