diff options
author | Paul Holzinger <pholzing@redhat.com> | 2022-06-16 16:20:30 +0200 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2022-06-16 16:59:47 +0200 |
commit | 09c462d735082efa0489b66c66f0590460f4f00c (patch) | |
tree | 6f13726227d9ac4c6ab649b0953f6f504a2a4637 | |
parent | 82936d89887d8a649c6e439cef85304882c44c46 (diff) | |
download | podman-09c462d735082efa0489b66c66f0590460f4f00c.tar.gz podman-09c462d735082efa0489b66c66f0590460f4f00c.tar.bz2 podman-09c462d735082efa0489b66c66f0590460f4f00c.zip |
fix "podman -h" help output
`podman -h` currently returns an error:
`Error: pflag: help requested`
This bug was introduced in 44d037898ebc, the problem is that we wrap the
error and cobra lib checks with `==` for this one and not errors.Is().
I have a PR upstream to fix this but for now this also works.
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
-rw-r--r-- | cmd/podman/main.go | 9 | ||||
-rw-r--r-- | test/system/015-help.bats | 2 |
2 files changed, 10 insertions, 1 deletions
diff --git a/cmd/podman/main.go b/cmd/podman/main.go index 929c8a757..c6ba69e94 100644 --- a/cmd/podman/main.go +++ b/cmd/podman/main.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "os" @@ -26,6 +27,7 @@ import ( "github.com/containers/storage/pkg/reexec" "github.com/sirupsen/logrus" "github.com/spf13/cobra" + "github.com/spf13/pflag" ) func main() { @@ -101,6 +103,13 @@ func parseCommands() *cobra.Command { } func flagErrorFuncfunc(c *cobra.Command, e error) error { + // cobra compares via == and not errors.Is so we cannot wrap that error. + // This is required to make podman -h work. + // This can be removed once https://github.com/spf13/cobra/pull/1730 + // is merged and vendored into podman. + if errors.Is(e, pflag.ErrHelp) { + return e + } e = fmt.Errorf("%w\nSee '%s --help'", e, c.CommandPath()) return e } diff --git a/test/system/015-help.bats b/test/system/015-help.bats index 1356c99a0..dd5a7ed44 100644 --- a/test/system/015-help.bats +++ b/test/system/015-help.bats @@ -199,7 +199,7 @@ function check_help() { check_help # Test for regression of #7273 (spurious "--remote" help on output) - for helpopt in help --help; do + for helpopt in help --help -h; do run_podman $helpopt is "${lines[0]}" "Manage pods, containers and images" \ "podman $helpopt: first line of output" |