mirror of
https://github.com/kubernetes/kubectl.git
synced 2026-05-28 04:35:50 -04:00
Merge pull request #98301 from phil9909/bash-completion-multiple-resources
add bash-completion for comma separated list on `kubectl get` Kubernetes-commit: 25aa6cf0c58067656dd6e4c1e2c28efb259ab08c
This commit is contained in:
commit
ddb56dde55
4 changed files with 45 additions and 11 deletions
2
Godeps/Godeps.json
generated
2
Godeps/Godeps.json
generated
|
|
@ -928,7 +928,7 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery",
|
||||
"Rev": "527a61b4dffe"
|
||||
"Rev": "6d2f20b34738"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/cli-runtime",
|
||||
|
|
|
|||
4
go.mod
4
go.mod
|
|
@ -35,7 +35,7 @@ require (
|
|||
golang.org/x/sys v0.0.0-20201112073958-5cba982894dd
|
||||
gopkg.in/yaml.v2 v2.2.8
|
||||
k8s.io/api v0.0.0-20210218021651-498bb3d8b5a6
|
||||
k8s.io/apimachinery v0.0.0-20210217011835-527a61b4dffe
|
||||
k8s.io/apimachinery v0.0.0-20210219091810-6d2f20b34738
|
||||
k8s.io/cli-runtime v0.0.0-20210217222438-5dae1b234a43
|
||||
k8s.io/client-go v0.0.0-20210219052155-12449b5492ee
|
||||
k8s.io/component-base v0.0.0-20210217012751-bf61fcdb2cb3
|
||||
|
|
@ -50,7 +50,7 @@ require (
|
|||
|
||||
replace (
|
||||
k8s.io/api => k8s.io/api v0.0.0-20210218021651-498bb3d8b5a6
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20210217011835-527a61b4dffe
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20210219091810-6d2f20b34738
|
||||
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20210217222438-5dae1b234a43
|
||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20210219052155-12449b5492ee
|
||||
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20210217003918-5a6947c9f285
|
||||
|
|
|
|||
2
go.sum
2
go.sum
|
|
@ -625,7 +625,7 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
|
|||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
k8s.io/api v0.0.0-20210218021651-498bb3d8b5a6/go.mod h1:60tmSUpHxGPFerNHbo/ayI2lKxvtrhbxFyXuEIWJd78=
|
||||
k8s.io/apimachinery v0.0.0-20210217011835-527a61b4dffe/go.mod h1:Z7ps/g0rjlTeMstYrMOUttJfT2Gg34DEaG/f2PYLCWY=
|
||||
k8s.io/apimachinery v0.0.0-20210219091810-6d2f20b34738/go.mod h1:Z7ps/g0rjlTeMstYrMOUttJfT2Gg34DEaG/f2PYLCWY=
|
||||
k8s.io/cli-runtime v0.0.0-20210217222438-5dae1b234a43/go.mod h1:iMyecOoB0p2BUHXHKs6c0elbq/BVQYazlvwURVfjtkM=
|
||||
k8s.io/client-go v0.0.0-20210219052155-12449b5492ee/go.mod h1:VGRl84/71eS0xitGML6HKUOweoHe0JXXz0WOkwRBqtc=
|
||||
k8s.io/code-generator v0.0.0-20210217003918-5a6947c9f285/go.mod h1:O7FXIFFMbeLstjVDD1gKtnexuIo2JF8jkudWpXyjVeo=
|
||||
|
|
|
|||
|
|
@ -152,19 +152,49 @@ __kubectl_parse_get()
|
|||
fi
|
||||
}
|
||||
|
||||
# Same as __kubectl_get_resources (with s) but allows completion for only one resource name.
|
||||
__kubectl_get_resource()
|
||||
{
|
||||
if [[ ${#nouns[@]} -eq 0 ]]; then
|
||||
local kubectl_out
|
||||
if kubectl_out=$(__kubectl_debug_out "kubectl api-resources $(__kubectl_override_flags) -o name --cached --request-timeout=5s --verbs=get"); then
|
||||
COMPREPLY=( $( compgen -W "${kubectl_out[*]}" -- "$cur" ) )
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
__kubectl_get_resource_helper "" "$cur"
|
||||
return # the return status is that of the last command executed in the function body
|
||||
fi
|
||||
__kubectl_parse_get "${nouns[${#nouns[@]} -1]}"
|
||||
}
|
||||
|
||||
# Same as __kubectl_get_resource (without s) but allows completion for multiple, comma-separated resource names.
|
||||
__kubectl_get_resources()
|
||||
{
|
||||
local SEPARATOR=','
|
||||
if [[ ${#nouns[@]} -eq 0 ]]; then
|
||||
local kubectl_out HEAD TAIL
|
||||
HEAD=""
|
||||
TAIL="$cur"
|
||||
# if SEPARATOR is contained in $cur, e.g. "pod,sec"
|
||||
if [[ "$cur" = *${SEPARATOR}* ]] ; then
|
||||
# set HEAD to "pod,"
|
||||
HEAD="${cur%${SEPARATOR}*}${SEPARATOR}"
|
||||
# set TAIL to "sec"
|
||||
TAIL="${cur##*${SEPARATOR}}"
|
||||
fi
|
||||
__kubectl_get_resource_helper "$HEAD" "$TAIL"
|
||||
return # the return status is that of the last command executed in the function body
|
||||
fi
|
||||
__kubectl_parse_get "${nouns[${#nouns[@]} -1]}"
|
||||
}
|
||||
|
||||
__kubectl_get_resource_helper()
|
||||
{
|
||||
local kubectl_out HEAD TAIL
|
||||
HEAD="$1"
|
||||
TAIL="$2"
|
||||
if kubectl_out=$(__kubectl_debug_out "kubectl api-resources $(__kubectl_override_flags) -o name --cached --request-timeout=5s --verbs=get"); then
|
||||
COMPREPLY=( $( compgen -P "$HEAD" -W "${kubectl_out[*]}" -- "$TAIL" ) )
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
__kubectl_get_resource_namespace()
|
||||
{
|
||||
__kubectl_parse_get "namespace"
|
||||
|
|
@ -251,7 +281,11 @@ __kubectl_cp()
|
|||
|
||||
__kubectl_custom_func() {
|
||||
case ${last_command} in
|
||||
kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_edit | kubectl_patch |\
|
||||
kubectl_get)
|
||||
__kubectl_get_resources
|
||||
return
|
||||
;;
|
||||
kubectl_describe | kubectl_delete | kubectl_label | kubectl_edit | kubectl_patch |\
|
||||
kubectl_annotate | kubectl_expose | kubectl_scale | kubectl_autoscale | kubectl_taint | kubectl_rollout_* |\
|
||||
kubectl_apply_edit-last-applied | kubectl_apply_view-last-applied)
|
||||
__kubectl_get_resource
|
||||
|
|
|
|||
Loading…
Reference in a new issue