Add awareness of more override flags in bash-completion

This commit is contained in:
Dr. Stefan Schimanski 2016-04-04 21:04:00 +02:00 committed by Dr. Stefan Schimanski
parent f3359fe134
commit e78d7749a5

View File

@ -32,30 +32,35 @@ import (
const ( const (
bash_completion_func = `# call kubectl get $1, bash_completion_func = `# call kubectl get $1,
__kubectl_namespace_flag() __kubectl_override_flag_list=(kubeconfig cluster user context namespace server)
__kubectl_override_flags()
{ {
local ret two_word_ns local ${__kubectl_override_flag_list[*]} two_word_of of
ret=""
two_word_ns=false
for w in "${words[@]}"; do for w in "${words[@]}"; do
if [ "$two_word_ns" = true ]; then if [ -n "${two_word_of}" ]; then
ret="--namespace=${w}" eval "${two_word_of}=\"--${two_word_of}=\${w}\""
two_word_ns=false two_word_of=
continue continue
fi fi
case "${w}" in for of in "${__kubectl_override_flag_list[@]}"; do
--namespace=*) case "${w}" in
ret=${w} --${of}=*)
;; eval "${of}=\"--${of}=\${w}\""
--namespace) ;;
two_word_ns=true --${of})
;; two_word_of="${of}"
--all-namespaces) ;;
ret=${w} esac
;; done
esac if [ "${w}" == "--all-namespaces" ]; then
namespace="--all-namespaces"
fi
done
for of in "${__kubectl_override_flag_list[@]}"; do
if eval "test -n \"\$${of}\""; then
eval "echo \${${of}}"
fi
done done
echo $ret
} }
__kubectl_get_namespaces() __kubectl_get_namespaces()
@ -72,7 +77,7 @@ __kubectl_parse_get()
local template local template
template="{{ range .items }}{{ .metadata.name }} {{ end }}" template="{{ range .items }}{{ .metadata.name }} {{ end }}"
local kubectl_out local kubectl_out
if kubectl_out=$(kubectl get $(__kubectl_namespace_flag) -o template --template="${template}" "$1" 2>/dev/null); then if kubectl_out=$(kubectl get $(__kubectl_override_flags) -o template --template="${template}" "$1" 2>/dev/null); then
COMPREPLY=( $( compgen -W "${kubectl_out[*]}" -- "$cur" ) ) COMPREPLY=( $( compgen -W "${kubectl_out[*]}" -- "$cur" ) )
fi fi
} }