From cc875fd26848e74e4a70e9929c0e7e855a758970 Mon Sep 17 00:00:00 2001 From: Markus Thömmes Date: Wed, 13 Oct 2021 11:46:46 +0200 Subject: Display help text on empty subcommand by default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Markus Thömmes --- cmd/podman/validate/args.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/podman/validate/args.go b/cmd/podman/validate/args.go index fc07a6acc..dde45cc29 100644 --- a/cmd/podman/validate/args.go +++ b/cmd/podman/validate/args.go @@ -27,7 +27,7 @@ func SubCommandExists(cmd *cobra.Command, args []string) error { } return errors.Errorf("unrecognized command `%[1]s %[2]s`\n\nDid you mean this?\n\t%[3]s\n\nTry '%[1]s --help' for more information.", cmd.CommandPath(), args[0], strings.Join(suggestions, "\n\t")) } - return errors.Errorf("missing command '%[1]s COMMAND'\nTry '%[1]s --help' for more information.", cmd.CommandPath()) + return cmd.Help() } // IDOrLatestArgs used to validate a nameOrId was provided or the "--latest" flag -- cgit v1.2.3-54-g00ecf From 184de3955ca8cb57e091a1b6006514aade885a59 Mon Sep 17 00:00:00 2001 From: Markus Thömmes Date: Thu, 14 Oct 2021 13:42:04 +0200 Subject: Adjust tests to verify all subcommands show the help message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Markus Thömmes --- test/system/001-basic.bats | 6 ++---- test/system/015-help.bats | 13 ++++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/test/system/001-basic.bats b/test/system/001-basic.bats index 2e5ebe4a3..2a6f4bea0 100644 --- a/test/system/001-basic.bats +++ b/test/system/001-basic.bats @@ -100,10 +100,8 @@ function setup() { skip "only applicable on a local run since this requires no endpoint" fi - run_podman 125 --remote - is "$output" "Error: missing command 'podman COMMAND' -Try 'podman --help' for more information." \ - "podman --remote show usage message without running endpoint" + run_podman --remote + is "$output" ".*Usage:" "podman --remote show usage message without running endpoint" } # This is for development only; it's intended to make sure our timeout diff --git a/test/system/015-help.bats b/test/system/015-help.bats index 5f38c34a1..51660ba12 100644 --- a/test/system/015-help.bats +++ b/test/system/015-help.bats @@ -143,13 +143,16 @@ function check_help() { count=$(expr $count + 1) done - # Any command that takes subcommands, must throw error if called + # Any command that takes subcommands, prints its help if called # without one. dprint "podman $@" - run_podman '?' "$@" - is "$status" 125 "'podman $*' without any subcommand - exit status" - is "$output" "Error: missing command .*$@ COMMAND" \ - "'podman $*' without any subcommand - expected error message" + + # Store the output of the actual --help command + run_podman "$@" --help + local full_help="$output" + + run_podman "$@" + is "$output" "$full_help" "'podman $*' without any subcommand - expected help message" # Assume that 'NoSuchCommand' is not a command dprint "podman $@ NoSuchCommand" -- cgit v1.2.3-54-g00ecf From 756dda298c76b54a4401b7497bbff297dcf4014f Mon Sep 17 00:00:00 2001 From: Markus Thömmes Date: Thu, 4 Nov 2021 16:12:34 +0100 Subject: Keep error semantics intact MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Markus Thömmes --- cmd/podman/validate/args.go | 3 ++- test/system/001-basic.bats | 2 +- test/system/015-help.bats | 13 +++++-------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/cmd/podman/validate/args.go b/cmd/podman/validate/args.go index dde45cc29..6b5425a69 100644 --- a/cmd/podman/validate/args.go +++ b/cmd/podman/validate/args.go @@ -27,7 +27,8 @@ func SubCommandExists(cmd *cobra.Command, args []string) error { } return errors.Errorf("unrecognized command `%[1]s %[2]s`\n\nDid you mean this?\n\t%[3]s\n\nTry '%[1]s --help' for more information.", cmd.CommandPath(), args[0], strings.Join(suggestions, "\n\t")) } - return cmd.Help() + cmd.Help() + return errors.Errorf("missing command '%[1]s COMMAND'", cmd.CommandPath()) } // IDOrLatestArgs used to validate a nameOrId was provided or the "--latest" flag diff --git a/test/system/001-basic.bats b/test/system/001-basic.bats index 2a6f4bea0..ccc05bb15 100644 --- a/test/system/001-basic.bats +++ b/test/system/001-basic.bats @@ -100,7 +100,7 @@ function setup() { skip "only applicable on a local run since this requires no endpoint" fi - run_podman --remote + run_podman 125 --remote is "$output" ".*Usage:" "podman --remote show usage message without running endpoint" } diff --git a/test/system/015-help.bats b/test/system/015-help.bats index 51660ba12..b2c6e2575 100644 --- a/test/system/015-help.bats +++ b/test/system/015-help.bats @@ -143,16 +143,13 @@ function check_help() { count=$(expr $count + 1) done - # Any command that takes subcommands, prints its help if called + # Any command that takes subcommands, prints its help and errors if called # without one. dprint "podman $@" - - # Store the output of the actual --help command - run_podman "$@" --help - local full_help="$output" - - run_podman "$@" - is "$output" "$full_help" "'podman $*' without any subcommand - expected help message" + run_podman '?' "$@" + is "$status" 125 "'podman $*' without any subcommand - exit status" + is "$output" ".*Usage:.*Error: missing command '.*$@ COMMAND'" \ + "'podman $*' without any subcommand - expected error message" # Assume that 'NoSuchCommand' is not a command dprint "podman $@ NoSuchCommand" -- cgit v1.2.3-54-g00ecf