mirror of
https://github.com/kubernetes/kubectl.git
synced 2026-05-28 04:35:50 -04:00
Add diff command return status code greater than 1 when flags invalid
This PR adds flagerror handler function to detect when flags are invalid. Default flag handler returns status code 1. However, diff command embraces this status code as changes are found. By overriding flag errors, this PR shows same message with default case and returns status code 2. Kubernetes-commit: 4f0848520d4cdd679c76479949546002c5935e3c
This commit is contained in:
parent
a8d3024f11
commit
8307ca4a3c
1 changed files with 8 additions and 0 deletions
|
|
@ -160,6 +160,14 @@ func NewCmdDiff(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.C
|
|||
},
|
||||
}
|
||||
|
||||
// Flag errors exit with code 1, however according to the diff
|
||||
// command it means changes were found.
|
||||
// Thus, it should return status code greater than 1.
|
||||
cmd.SetFlagErrorFunc(func(command *cobra.Command, err error) error {
|
||||
cmdutil.CheckDiffErr(cmdutil.UsageErrorf(cmd, err.Error()))
|
||||
return nil
|
||||
})
|
||||
|
||||
usage := "contains the configuration to diff"
|
||||
cmd.Flags().StringVarP(&options.Selector, "selector", "l", options.Selector, "Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)")
|
||||
cmdutil.AddFilenameOptionFlags(cmd, &options.FilenameOptions, usage)
|
||||
|
|
|
|||
Loading…
Reference in a new issue