summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2022-02-21 16:28:04 +0100
committerPaul Holzinger <pholzing@redhat.com>2022-02-21 19:12:12 +0100
commit44d037898ebc328432823d51ca2da298902a46e9 (patch)
tree68ed394ca8fb0d6fc58499ab35053811ebc4feb9 /cmd
parentd224a0f8ac4978c3ac399a0940f785892d63daa8 (diff)
downloadpodman-44d037898ebc328432823d51ca2da298902a46e9.tar.gz
podman-44d037898ebc328432823d51ca2da298902a46e9.tar.bz2
podman-44d037898ebc328432823d51ca2da298902a46e9.zip
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>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/main.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/cmd/podman/main.go b/cmd/podman/main.go
index 9850f5d27..4f8131653 100644
--- a/cmd/podman/main.go
+++ b/cmd/podman/main.go
@@ -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
+}