clan: add dynamic completions for clan secrets import-sops

This commit is contained in:
a-kenji 2024-06-04 13:40:24 +02:00
parent 836170e5b6
commit 9dbbb6f2f6

View File

@ -3,6 +3,12 @@ import json
import sys import sys
from pathlib import Path from pathlib import Path
from ..completions import (
add_dynamic_completer,
complete_groups,
complete_machines,
complete_users,
)
from ..cmd import run from ..cmd import run
from ..errors import ClanError from ..errors import ClanError
from ..nix import nix_shell from ..nix import nix_shell
@ -57,27 +63,30 @@ def register_import_sops_parser(parser: argparse.ArgumentParser) -> None:
default=None, default=None,
help="the input type of the sops file (yaml, json, ...). If not specified, it will be guessed from the file extension", help="the input type of the sops file (yaml, json, ...). If not specified, it will be guessed from the file extension",
) )
parser.add_argument( group_action = parser.add_argument(
"--group", "--group",
type=str, type=str,
action="append", action="append",
default=[], default=[],
help="the group to import the secrets to", help="the group to import the secrets to",
) )
parser.add_argument( add_dynamic_completer(group_action, complete_groups)
machine_action = parser.add_argument(
"--machine", "--machine",
type=str, type=str,
action="append", action="append",
default=[], default=[],
help="the machine to import the secrets to", help="the machine to import the secrets to",
) )
parser.add_argument( add_dynamic_completer(machine_action, complete_machines)
user_action = parser.add_argument(
"--user", "--user",
type=str, type=str,
action="append", action="append",
default=[], default=[],
help="the user to import the secrets to", help="the user to import the secrets to",
) )
add_dynamic_completer(user_action, complete_users)
parser.add_argument( parser.add_argument(
"--prefix", "--prefix",
type=str, type=str,