-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
k8s-vault-completion.bash
68 lines (67 loc) · 1.49 KB
/
k8s-vault-completion.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
if [[ -z "${K8SVAULT_CONFIG_DIR:-}" ]]; then
K8SVAULT_CONFIG_DIR="${HOME}/.kube"
fi
if [[ -z "${K8SVAULT_CONFIG:-}" ]]; then
K8SVAULT_CONFIG="${K8SVAULT_CONFIG_DIR}/k8s-vault.yaml"
fi
COMPREPLY=()
if ! command -v k8s-vault >/dev/null; then
echo >&2 "ERROR: k8s-vault is missing in PATH"
return 1
fi
for dep in ${DEPS[*]}; do
check_dep $dep
done
if [ ! -r "${K8SVAULT_CONFIG}" ]; then
echo >&2 "ERROR: unable to read K8SVAULT_CONFIG at \"${K8SVAULT_CONFIG}\""
return 1
fi
_k8svault_get_contexts()
{
local contexts
if contexts=$(k8s-vault list-enabled-contexts); then
COMPREPLY+=( $(compgen -W "${contexts[*]}" -- "${_word_last}") )
fi
}
_k8svault_completion()
{
local _word_index=$[${COMP_CWORD}-1]
local _word="${COMP_WORDS[$_word_index]}"
local _word_last="${COMP_WORDS[-1]}"
case $_word in
k8s-vault)
COMPREPLY+=( $(compgen -W "--debug exec completion example-config" -- "${_word_last}") )
return
;;
--debug)
COMPREPLY=( $(compgen -W "exec completion example-config" -- "${_word_last}") )
return
;;
completion)
return
;;
example-config)
return
;;
exec)
_k8svault_get_contexts
return
;;
-*)
return
;;
\>*)
return
;;
*)
COMPREPLY=( -s -- )
return
;;
esac
}
if [[ $(type -t compopt) = "builtin" ]]; then
complete -o default -F _k8svault_completion k8s-vault
else
complete -o default -o nospace -F _k8svault_completion k8s-vault
fi