fix kubectl config return 0 on error

This commit is contained in:
shiywang
2017-03-14 00:02:00 +08:00
parent 302aab9ba2
commit 917a0b6f1b
7 changed files with 29 additions and 46 deletions

View File

@@ -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 {