diff --git a/pkgs/clan-cli/clan_cli/clan/create.py b/pkgs/clan-cli/clan_cli/clan/create.py index c4beeccd5..25a939136 100644 --- a/pkgs/clan-cli/clan_cli/clan/create.py +++ b/pkgs/clan-cli/clan_cli/clan/create.py @@ -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 '#template_name' Where 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", diff --git a/pkgs/clan-cli/clan_cli/completions.py b/pkgs/clan-cli/clan_cli/completions.py index 6b965e081..c0b8dc981 100644 --- a/pkgs/clan-cli/clan_cli/completions.py +++ b/pkgs/clan-cli/clan_cli/completions.py @@ -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]: