pkgs/clan(templates): Add shell completions

This commit is contained in:
a-kenji
2025-07-12 15:11:17 +02:00
parent a890b586b4
commit dc915387d9
2 changed files with 26 additions and 1 deletions

View File

@@ -249,6 +249,26 @@ def complete_groups(
return groups_dict
def complete_templates_disko(
prefix: str, parsed_args: argparse.Namespace, **kwargs: Any
) -> Iterable[str]:
"""
Provides completion functionality for disko 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))
disko_template_list = list_all_templates.builtins.get("disko")
if disko_template_list:
disko_templates = list(disko_template_list)
disko_dict = dict.fromkeys(disko_templates, "disko")
return disko_dict
return []
def complete_target_host(
prefix: str, parsed_args: argparse.Namespace, **kwargs: Any
) -> Iterable[str]:

View File

@@ -6,6 +6,8 @@ from typing import Any
from clan_lib.api.disk import set_machine_disk_schema
from clan_lib.machines.machines import Machine
from clan_cli.completions import add_dynamic_completer, complete_templates_disko
log = logging.getLogger(__name__)
@@ -48,12 +50,15 @@ def register_apply_disk_template_parser(parser: argparse.ArgumentParser) -> None
required=True,
help="The machine to apply the template to",
)
parser.add_argument(
template_action = parser.add_argument(
"--template",
type=str,
required=True,
help="The name of the disk template to apply",
)
add_dynamic_completer(template_action, complete_templates_disko)
parser.add_argument(
"--set",
help="Set a placeholder in the template to a value",