[cli] exit when Validate() return an error

cmdutil.UsageErrorf() does nothing but return a string. When Validate()
returns an error, we should call exit() function.
This commit is contained in:
Cao Shufeng 2017-08-26 17:43:46 +08:00
parent 43559fe9df
commit 26032ad6f8
2 changed files with 3 additions and 3 deletions

View File

@ -43,7 +43,7 @@ const (
var ( var (
renameContextLong = templates.LongDesc(` renameContextLong = templates.LongDesc(`
Renames a context from the kubeconfig file . Renames a context from the kubeconfig file.
CONTEXT_NAME is the context name that you wish change. CONTEXT_NAME is the context name that you wish change.
@ -70,7 +70,7 @@ func NewCmdConfigRenameContext(out io.Writer, configAccess clientcmd.ConfigAcces
cmdutil.CheckErr(err) cmdutil.CheckErr(err)
} }
if err := options.Validate(); err != nil { if err := options.Validate(); err != nil {
cmdutil.UsageErrorf(cmd, err.Error()) cmdutil.CheckErr(cmdutil.UsageErrorf(cmd, err.Error()))
} }
if err := options.RunRenameContext(out); err != nil { if err := options.RunRenameContext(out); err != nil {
cmdutil.CheckErr(err) cmdutil.CheckErr(err)

View File

@ -124,7 +124,7 @@ func (o *ConvertOptions) Complete(f cmdutil.Factory, out io.Writer, cmd *cobra.C
return err return err
} }
if !scheme.Registry.IsEnabledVersion(o.outputVersion) { if !scheme.Registry.IsEnabledVersion(o.outputVersion) {
cmdutil.UsageErrorf(cmd, "'%s' is not a registered version.", o.outputVersion) return cmdutil.UsageErrorf(cmd, "'%s' is not a registered version.", o.outputVersion)
} }
// build the builder // build the builder