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:
Arda Güçlü 2021-10-04 13:02:34 +03:00 committed by Kubernetes Publisher
parent a8d3024f11
commit 8307ca4a3c

View file

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