mirror of
https://github.com/containers/podman.git
synced 2025-12-07 14:20:44 +08:00
provide better error on invalid flag
Add a extra `See 'podman command --help'` to the error output. With this patch you now get: ``` $ podman run -h Error: flag needs an argument: 'h' in -h See 'podman run --help' ``` Fixes #13082 Fixes #13002 Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
@@ -72,6 +72,8 @@ func parseCommands() *cobra.Command {
|
||||
}
|
||||
parent.AddCommand(c.Command)
|
||||
|
||||
c.Command.SetFlagErrorFunc(flagErrorFuncfunc)
|
||||
|
||||
// - templates need to be set here, as PersistentPreRunE() is
|
||||
// not called when --help is used.
|
||||
// - rootCmd uses cobra default template not ours
|
||||
@@ -84,5 +86,11 @@ func parseCommands() *cobra.Command {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
rootCmd.SetFlagErrorFunc(flagErrorFuncfunc)
|
||||
return rootCmd
|
||||
}
|
||||
|
||||
func flagErrorFuncfunc(c *cobra.Command, e error) error {
|
||||
e = fmt.Errorf("%w\nSee '%s --help'", e, c.CommandPath())
|
||||
return e
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user