mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00: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.
This commit is contained in:
parent
0ac956ff2b
commit
4f0848520d
@ -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 New Issue
Block a user