mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 07:57:35 +00:00
fix kubectl config return 0 on error
This commit is contained in:
@@ -50,10 +50,7 @@ func NewCmdConfigUseContext(out io.Writer, configAccess clientcmd.ConfigAccess)
|
||||
Long: `Sets the current-context in a kubeconfig file`,
|
||||
Example: use_context_example,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if !options.complete(cmd) {
|
||||
return
|
||||
}
|
||||
|
||||
cmdutil.CheckErr(options.complete(cmd))
|
||||
cmdutil.CheckErr(options.run())
|
||||
fmt.Fprintf(out, "Switched to context %q.\n", options.contextName)
|
||||
},
|
||||
@@ -82,15 +79,15 @@ func (o useContextOptions) run() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *useContextOptions) complete(cmd *cobra.Command) bool {
|
||||
func (o *useContextOptions) complete(cmd *cobra.Command) error {
|
||||
endingArgs := cmd.Flags().Args()
|
||||
if len(endingArgs) != 1 {
|
||||
cmd.Help()
|
||||
return false
|
||||
return fmt.Errorf("Unexpected args: %v", endingArgs)
|
||||
}
|
||||
|
||||
o.contextName = endingArgs[0]
|
||||
return true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o useContextOptions) validate(config *clientcmdapi.Config) error {
|
||||
|
||||
Reference in New Issue
Block a user