keymgr-completion.zsh 3.28 KB
Newer Older
1 2 3
#compdef keymgr


4
local -a matchany policy_list policies zone_list zones files
5
matchany=(/$'[^\0]##\0'/)
6 7 8
key_list=( \( $(keymgr keystore list 2>/dev/null) \) )
keys=( \( $matchany ":keys:keys:$key_list" \) )
policy_list=( \( $(keymgr policy list 2>/dev/null) \) )
9
policies=( \( $matchany ":policies:policies:$policy_list" \) )
10
zone_list=( \( $(keymgr zone list 2>/dev/null) \) )
11
zones=( \( $matchany ":zones:zones:$zone_list" \) )
12
files=(/$'[^\0]##\0'/ ':file:file name:_files')
13 14 15

local -a keystore_cmds
_regex_words keystore-commands "keystore commands" \
16
	'l*ist:list all keys'
17 18
keystore_cmds=("$reply[@]")

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
local -a policy_subcmds policy_add_cmds policy_set_cmds
_regex_words policy-add-commands "policy add commands" \
	'a*lgorithm' \
	'de*lay' \
	'dn*skey-ttl' \
	'k*sk-size' \
	'n*sec3' \
	'rrsig-l*ifetime' \
	'rrsig-r*efresh' \
	's*oa-min-ttl' \
	'zo*ne-max-ttl' \
	'zsk-l*ifetime' \
	'zsk-s*ize'
policy_subcmds=("$reply[@]")
policy_add_cmds=( $matchany $policy_subcmds )
policy_set_cmds=( $policies $policy_subcmds )

36 37
local -a policy_cmds
_regex_words policy-commands "policy commands" \
38
	'a*dd:add a policy:$policy_add_cmds' \
39 40
	'l*ist:list all added policies' \
	'r*emove:remove a policy:$policies' \
41 42
	'se*t:set policy attributes:$policy_set_cmds' \
	'sh*ow:show policy attributes:$policies'
43 44
policy_cmds=("$reply[@]")

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
local -a zone_add_cmds
_regex_words zone-add-commands "zone add commands" \
	'p*olicy:set zone policy:$policies'
zone_add_cmds=( $matchany "$reply[@]")

local -a zone_key_generate_cmds
_regex_words zone-key-generate-commands "zone key generate commands" \
	'ac*tive' \
	'al*gorithm' \
	'k*sk' \
	'p*ublish' \
	'rem*ove' \
	'ret*ire' \
	's*ize'
zone_key_generate_cmds=( $matchany "$reply[@]")

local -a zone_key_import_cmds
zone_key_import_cmds=( $zones $files )

local -a zone_key_set_cmds
_regex_words zone-key-set-commands "zone key set commands" \
	'a*ctive' \
	'p*ublish' \
	'rem*ove' \
	'ret*ire'
zone_key_set_cmds=( $zones "$reply[@]")

local -a zone_key_cmds
_regex_words zone-key-commands "zone key commands" \
	'g*enerate:generate a key:$zone_key_generate_cmds' \
	'i*mport:import keys from file:$zone_key_import_cmds' \
	'l*ist:list keys:$zones' \
	'sh*ow:show a key:$zones' \
	'se*t:set attributes of a key:$zone_key_set_cmds'
zone_key_cmds=("$reply[@]")

local -a zone_remove_cmds
_regex_words zone-remove-commands "zone remove commands" \
	'f*orce:force remove'
zone_remove_cmds=( $zones "$reply[@]")

local -a zone_set_cmds
_regex_words zone-set-commands "zone set commands" \
	'p*olicy:set zone policy:$policies'
zone_set_cmds=( $zones "$reply[@]")

91 92
local -a zone_cmds
_regex_words zone-commands "zone commands" \
93 94
	'a*dd:add a zone:$zone_add_cmds' \
	'k*ey:manipulate zone keys:$zone_key_cmds' \
95 96
	'l*ist:list all added zones' \
	'r*emove:remove a zone:$zones' \
97
	'se*t:set zone attributes:$zone_set_cmds' \
98
	'sh*ow:show zone attributes:$zones'
99 100 101 102 103 104 105 106
zone_cmds=("$reply[@]")

# Arguments to _regex_arguments, built up in array $args.
local -a args reply
# Command word.  Don't care what that is.
args=( $matchany )

_regex_words commands "keymgr command" \
107 108 109 110
	'i*nit:initialize KASP directory and default keystore' \
	'k*eystore:manipulate keystore:$keystore_cmds' \
	'p*olicy:manipulate policies:$policy_cmds' \
	'z*one:manipule zones:$zone_cmds'
111 112 113 114 115
args+=("$reply[@]")

_regex_arguments _keymgr "${args[@]}"

_keymgr "$@"