mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Merge pull request #107142 from dimbleby/delete-user-completion
Completions for kubectl config delete-user
This commit is contained in:
commit
31dba0a435
@ -25,6 +25,7 @@ import (
|
|||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||||
|
"k8s.io/kubectl/pkg/util"
|
||||||
"k8s.io/kubectl/pkg/util/i18n"
|
"k8s.io/kubectl/pkg/util/i18n"
|
||||||
"k8s.io/kubectl/pkg/util/templates"
|
"k8s.io/kubectl/pkg/util/templates"
|
||||||
)
|
)
|
||||||
@ -64,6 +65,7 @@ func NewCmdConfigDeleteUser(streams genericclioptions.IOStreams, configAccess cl
|
|||||||
Short: i18n.T("Delete the specified user from the kubeconfig"),
|
Short: i18n.T("Delete the specified user from the kubeconfig"),
|
||||||
Long: i18n.T("Delete the specified user from the kubeconfig."),
|
Long: i18n.T("Delete the specified user from the kubeconfig."),
|
||||||
Example: deleteUserExample,
|
Example: deleteUserExample,
|
||||||
|
ValidArgsFunction: util.UserCompletionFunc,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
cmdutil.CheckErr(o.Complete(cmd, args))
|
cmdutil.CheckErr(o.Complete(cmd, args))
|
||||||
cmdutil.CheckErr(o.Validate())
|
cmdutil.CheckErr(o.Validate())
|
||||||
|
@ -131,6 +131,15 @@ func ClusterCompletionFunc(cmd *cobra.Command, args []string, toComplete string)
|
|||||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UserCompletionFunc is a completion function that completes as a first argument the
|
||||||
|
// user names that match the toComplete prefix
|
||||||
|
func UserCompletionFunc(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
if len(args) == 0 {
|
||||||
|
return ListUsersInConfig(toComplete), cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
|
||||||
// ListContextsInConfig returns a list of context names which begin with `toComplete`
|
// ListContextsInConfig returns a list of context names which begin with `toComplete`
|
||||||
func ListContextsInConfig(toComplete string) []string {
|
func ListContextsInConfig(toComplete string) []string {
|
||||||
config, err := factory.ToRawKubeConfigLoader().RawConfig()
|
config, err := factory.ToRawKubeConfigLoader().RawConfig()
|
||||||
|
Loading…
Reference in New Issue
Block a user