pkgs/clan(templates): Add shell completions
This commit is contained in:
@@ -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]:
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user