diff --git a/pkg/cli/environment.go b/pkg/cli/environment.go index b0463d01f..6a399d412 100644 --- a/pkg/cli/environment.go +++ b/pkg/cli/environment.go @@ -152,6 +152,7 @@ func New() *EnvSettings { func (s *EnvSettings) AddFlags(fs *pflag.FlagSet) { fs.StringVarP(&s.namespace, "namespace", "n", s.namespace, "namespace scope for this request") fs.StringVar(&s.KubeConfig, "kubeconfig", "", "path to the kubeconfig file") + fs.StringVar(&s.KubeContext, "context", s.KubeContext, "name of the kubeconfig context to use (alias for --kube-context)") fs.StringVar(&s.KubeContext, "kube-context", s.KubeContext, "name of the kubeconfig context to use") fs.StringVar(&s.KubeToken, "kube-token", s.KubeToken, "bearer token used for authentication") fs.StringVar(&s.KubeAsUser, "kube-as-user", s.KubeAsUser, "username to impersonate for the operation") diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go index dbedca026..9e6a721e5 100644 --- a/pkg/cmd/root.go +++ b/pkg/cmd/root.go @@ -233,8 +233,8 @@ func newRootCmdWithConfig(actionConfig *action.Configuration, out io.Writer, arg log.Fatal(err) } - // Setup shell completion for the kube-context flag - err = cmd.RegisterFlagCompletionFunc("kube-context", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { + // Setup shell completion for the kube-context flag (and its --context alias) + kubeContextCompletionFunc := func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { cobra.CompDebugln("About to get the different kube-contexts", settings.Debug) loadingRules := clientcmd.NewDefaultClientConfigLoadingRules() @@ -251,7 +251,12 @@ func newRootCmdWithConfig(actionConfig *action.Configuration, out io.Writer, arg return comps, cobra.ShellCompDirectiveNoFileComp } return nil, cobra.ShellCompDirectiveNoFileComp - }) + } + err = cmd.RegisterFlagCompletionFunc("kube-context", kubeContextCompletionFunc) + if err != nil { + log.Fatal(err) + } + err = cmd.RegisterFlagCompletionFunc("context", kubeContextCompletionFunc) if err != nil { log.Fatal(err) }