Unverified Commit 7f9f847c authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #54406 from superbrothers/kubectl-override-short-flags

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Improve 'kubectl completion` to override short flags **What this PR does / why we need it**: This PR improves `kubectl completion` to override short flags in addition to long flags. I tested this PR in both bash and zsh. ``` # Complete pods name in the `default` namespace $ kubectl get po nginx-4217019353-<tab> nginx-4217019353-mw1pk nginx-4217019353-rzw2c # Complete pods name in the `kube-system` namepace due to overriding the namespace $ kubectl -n kube-system get po kube<tab> kube-addon-manager-minikube kube-dns-910330662-l9pwt kubernetes-dashboard-9fbhm ``` **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
parents 705de0a9 d2816bc1
......@@ -37,22 +37,22 @@ import (
const (
bashCompletionFunc = `# call kubectl get $1,
__kubectl_override_flag_list=(kubeconfig cluster user context namespace server)
__kubectl_override_flag_list=(--kubeconfig --cluster --user --context --namespace --server -n -s)
__kubectl_override_flags()
{
local ${__kubectl_override_flag_list[*]} two_word_of of
local ${__kubectl_override_flag_list[*]##*-} two_word_of of var
for w in "${words[@]}"; do
if [ -n "${two_word_of}" ]; then
eval "${two_word_of}=\"--${two_word_of}=\${w}\""
eval "${two_word_of##*-}=\"${two_word_of}=\${w}\""
two_word_of=
continue
fi
for of in "${__kubectl_override_flag_list[@]}"; do
case "${w}" in
--${of}=*)
eval "${of}=\"${w}\""
${of}=*)
eval "${of##*-}=\"${w}\""
;;
--${of})
${of})
two_word_of="${of}"
;;
esac
......@@ -61,9 +61,9 @@ __kubectl_override_flags()
namespace="--all-namespaces"
fi
done
for of in "${__kubectl_override_flag_list[@]}"; do
if eval "test -n \"\$${of}\""; then
eval "echo \${${of}}"
for var in "${__kubectl_override_flag_list[@]##*-}"; do
if eval "test -n \"\$${var}\""; then
eval "echo \${${var}}"
fi
done
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment