mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 01:40:07 +00:00
Support --context flag completion for kubectl
This commit is contained in:
parent
dbf5a40965
commit
4da41ca56c
@ -75,6 +75,15 @@ __kubectl_get_namespaces()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__kubectl_get_contexts()
|
||||||
|
{
|
||||||
|
local template kubectl_out
|
||||||
|
template="{{ range .contexts }}{{ .name }} {{ end }}"
|
||||||
|
if kubectl_out=$(kubectl config $(__kubectl_override_flags) -o template --template="${template}" view 2>/dev/null); then
|
||||||
|
COMPREPLY=( $( compgen -W "${kubectl_out[*]}" -- "$cur" ) )
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
__kubectl_parse_get()
|
__kubectl_parse_get()
|
||||||
{
|
{
|
||||||
local template
|
local template
|
||||||
@ -324,6 +333,16 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cmds.Flag("context") != nil {
|
||||||
|
if cmds.Flag("context").Annotations == nil {
|
||||||
|
cmds.Flag("context").Annotations = map[string][]string{}
|
||||||
|
}
|
||||||
|
cmds.Flag("context").Annotations[cobra.BashCompCustom] = append(
|
||||||
|
cmds.Flag("context").Annotations[cobra.BashCompCustom],
|
||||||
|
"__kubectl_get_contexts",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
cmds.AddCommand(cmdconfig.NewCmdConfig(clientcmd.NewDefaultPathOptions(), out, err))
|
cmds.AddCommand(cmdconfig.NewCmdConfig(clientcmd.NewDefaultPathOptions(), out, err))
|
||||||
cmds.AddCommand(NewCmdVersion(f, out))
|
cmds.AddCommand(NewCmdVersion(f, out))
|
||||||
cmds.AddCommand(NewCmdApiVersions(f, out))
|
cmds.AddCommand(NewCmdApiVersions(f, out))
|
||||||
|
Loading…
Reference in New Issue
Block a user