From 346dac74af018a968a7a42ecb8f84bcae0d337b7 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 5 Jul 2024 02:49:31 +0200 Subject: [PATCH] cli: improve argument validation output Improve the output for these validation errors: - Removes the short command description from the output. This information does not provide much useful help, and distracts from the error message. - Reduces punctuation, and - Prefixes the error message with the binary / root-command name (usually `docker:`) to be consistent with other similar errors. - Adds an empty line between the error-message and the "call to action" (`Run 'docker volume --help'...` in the example below). This helps separating the error message and "usage" from the call-to-action. Before this patch: $ docker volume ls one two three "docker volume ls" accepts no arguments. See 'docker volume ls --help'. Usage: docker volume ls [OPTIONS] List volumes $ docker volume create one two three "docker volume create" requires at most 1 argument. See 'docker volume create --help'. Usage: docker volume create [OPTIONS] [VOLUME] Create a volume With this patch: $ docker volume ls one two three docker: 'docker volume ls' accepts no arguments Usage: docker volume ls [OPTIONS] Run 'docker volume ls --help' for more information $ docker voludocker volume create one two three docker: 'docker volume create' requires at most 1 argument Usage: docker volume create [OPTIONS] [VOLUME] SRun 'docker volume create --help' for more information Signed-off-by: Sebastiaan van Stijn --- cli/command/checkpoint/create_test.go | 4 ++-- cli/command/checkpoint/list_test.go | 4 ++-- cli/command/checkpoint/remove_test.go | 4 ++-- cli/command/config/create_test.go | 4 ++-- cli/command/config/remove_test.go | 2 +- cli/command/image/history_test.go | 2 +- cli/command/image/import_test.go | 2 +- cli/command/image/inspect_test.go | 2 +- cli/command/image/list_test.go | 2 +- cli/command/image/load_test.go | 2 +- cli/command/image/prune_test.go | 2 +- cli/command/image/pull_test.go | 2 +- cli/command/image/push_test.go | 2 +- cli/command/image/remove_test.go | 2 +- cli/command/image/save_test.go | 2 +- cli/command/image/tag_test.go | 2 +- cli/command/manifest/annotate_test.go | 2 +- cli/command/manifest/push_test.go | 2 +- cli/command/network/connect_test.go | 2 +- cli/command/network/create_test.go | 2 +- cli/command/network/disconnect_test.go | 2 +- cli/command/node/update_test.go | 4 ++-- cli/command/plugin/disable_test.go | 4 ++-- cli/command/plugin/enable_test.go | 4 ++-- cli/command/secret/remove_test.go | 2 +- cli/command/service/rollback_test.go | 4 ++-- cli/command/stack/ps_test.go | 4 ++-- cli/command/swarm/join_test.go | 4 ++-- cli/command/swarm/join_token_test.go | 4 ++-- cli/command/trust/key_generate_test.go | 4 ++-- cli/command/trust/key_load_test.go | 5 +++-- cli/command/trust/revoke_test.go | 4 ++-- cli/command/trust/sign_test.go | 4 ++-- cli/required.go | 25 ++++++++++--------------- cli/required_test.go | 18 +++++++++--------- cmd/docker/docker_test.go | 2 +- e2e/cli-plugins/flags_test.go | 4 ++-- 37 files changed, 71 insertions(+), 75 deletions(-) diff --git a/cli/command/checkpoint/create_test.go b/cli/command/checkpoint/create_test.go index 3ad7922df64a..b3b737208093 100644 --- a/cli/command/checkpoint/create_test.go +++ b/cli/command/checkpoint/create_test.go @@ -20,11 +20,11 @@ func TestCheckpointCreateErrors(t *testing.T) { }{ { args: []string{"too-few-arguments"}, - expectedError: "requires exactly 2 arguments", + expectedError: "requires 2 arguments", }, { args: []string{"too", "many", "arguments"}, - expectedError: "requires exactly 2 arguments", + expectedError: "requires 2 arguments", }, { args: []string{"foo", "bar"}, diff --git a/cli/command/checkpoint/list_test.go b/cli/command/checkpoint/list_test.go index 7ac4a768de15..437cc1b359b0 100644 --- a/cli/command/checkpoint/list_test.go +++ b/cli/command/checkpoint/list_test.go @@ -20,11 +20,11 @@ func TestCheckpointListErrors(t *testing.T) { }{ { args: []string{}, - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { args: []string{"too", "many", "arguments"}, - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { args: []string{"foo"}, diff --git a/cli/command/checkpoint/remove_test.go b/cli/command/checkpoint/remove_test.go index 01bda3c04d2a..ae8402edb2be 100644 --- a/cli/command/checkpoint/remove_test.go +++ b/cli/command/checkpoint/remove_test.go @@ -19,11 +19,11 @@ func TestCheckpointRemoveErrors(t *testing.T) { }{ { args: []string{"too-few-arguments"}, - expectedError: "requires exactly 2 arguments", + expectedError: "requires 2 arguments", }, { args: []string{"too", "many", "arguments"}, - expectedError: "requires exactly 2 arguments", + expectedError: "requires 2 arguments", }, { args: []string{"foo", "bar"}, diff --git a/cli/command/config/create_test.go b/cli/command/config/create_test.go index db9f8eac8298..848f9c6e07af 100644 --- a/cli/command/config/create_test.go +++ b/cli/command/config/create_test.go @@ -28,11 +28,11 @@ func TestConfigCreateErrors(t *testing.T) { }{ { args: []string{"too_few"}, - expectedError: "requires exactly 2 arguments", + expectedError: "requires 2 arguments", }, { args: []string{"too", "many", "arguments"}, - expectedError: "requires exactly 2 arguments", + expectedError: "requires 2 arguments", }, { args: []string{"name", filepath.Join("testdata", configDataFile)}, diff --git a/cli/command/config/remove_test.go b/cli/command/config/remove_test.go index 1466391ee5db..d1c5a71f9f09 100644 --- a/cli/command/config/remove_test.go +++ b/cli/command/config/remove_test.go @@ -19,7 +19,7 @@ func TestConfigRemoveErrors(t *testing.T) { }{ { args: []string{}, - expectedError: "requires at least 1 argument.", + expectedError: "requires at least 1 argument", }, { args: []string{"foo"}, diff --git a/cli/command/image/history_test.go b/cli/command/image/history_test.go index 86eeaba3ba2e..5392f31eedec 100644 --- a/cli/command/image/history_test.go +++ b/cli/command/image/history_test.go @@ -23,7 +23,7 @@ func TestNewHistoryCommandErrors(t *testing.T) { { name: "wrong-args", args: []string{}, - expectedError: "requires exactly 1 argument.", + expectedError: "requires 1 argument.", }, { name: "client-error", diff --git a/cli/command/image/import_test.go b/cli/command/image/import_test.go index 59a6ced04d40..196171ed3121 100644 --- a/cli/command/image/import_test.go +++ b/cli/command/image/import_test.go @@ -22,7 +22,7 @@ func TestNewImportCommandErrors(t *testing.T) { { name: "wrong-args", args: []string{}, - expectedError: "requires at least 1 argument.", + expectedError: "requires at least 1 argument", }, { name: "import-failed", diff --git a/cli/command/image/inspect_test.go b/cli/command/image/inspect_test.go index 61ea36012e85..9e2163db5744 100644 --- a/cli/command/image/inspect_test.go +++ b/cli/command/image/inspect_test.go @@ -21,7 +21,7 @@ func TestNewInspectCommandErrors(t *testing.T) { { name: "wrong-args", args: []string{}, - expectedError: "requires at least 1 argument.", + expectedError: "requires at least 1 argument", }, } for _, tc := range testCases { diff --git a/cli/command/image/list_test.go b/cli/command/image/list_test.go index 4917c539398f..8ccec6ab567f 100644 --- a/cli/command/image/list_test.go +++ b/cli/command/image/list_test.go @@ -24,7 +24,7 @@ func TestNewImagesCommandErrors(t *testing.T) { { name: "wrong-args", args: []string{"arg1", "arg2"}, - expectedError: "requires at most 1 argument.", + expectedError: "requires at most 1 argument", }, { name: "failed-list", diff --git a/cli/command/image/load_test.go b/cli/command/image/load_test.go index 9c36ce32353b..5a8a499bda22 100644 --- a/cli/command/image/load_test.go +++ b/cli/command/image/load_test.go @@ -24,7 +24,7 @@ func TestNewLoadCommandErrors(t *testing.T) { { name: "wrong-args", args: []string{"arg"}, - expectedError: "accepts no arguments.", + expectedError: "accepts no arguments", }, { name: "input-to-terminal", diff --git a/cli/command/image/prune_test.go b/cli/command/image/prune_test.go index 1d6b2de983ad..710c1cf7482f 100644 --- a/cli/command/image/prune_test.go +++ b/cli/command/image/prune_test.go @@ -27,7 +27,7 @@ func TestNewPruneCommandErrors(t *testing.T) { { name: "wrong-args", args: []string{"something"}, - expectedError: "accepts no arguments.", + expectedError: "accepts no arguments", }, { name: "prune-error", diff --git a/cli/command/image/pull_test.go b/cli/command/image/pull_test.go index 43bc772ea75b..067006f16530 100644 --- a/cli/command/image/pull_test.go +++ b/cli/command/image/pull_test.go @@ -23,7 +23,7 @@ func TestNewPullCommandErrors(t *testing.T) { }{ { name: "wrong-args", - expectedError: "requires exactly 1 argument.", + expectedError: "requires 1 argument.", args: []string{}, }, { diff --git a/cli/command/image/push_test.go b/cli/command/image/push_test.go index a659c6c510cc..3ba0135ec0e9 100644 --- a/cli/command/image/push_test.go +++ b/cli/command/image/push_test.go @@ -21,7 +21,7 @@ func TestNewPushCommandErrors(t *testing.T) { { name: "wrong-args", args: []string{}, - expectedError: "requires exactly 1 argument.", + expectedError: "requires 1 argument.", }, { name: "invalid-name", diff --git a/cli/command/image/remove_test.go b/cli/command/image/remove_test.go index d4340b381914..0340a65b94cb 100644 --- a/cli/command/image/remove_test.go +++ b/cli/command/image/remove_test.go @@ -39,7 +39,7 @@ func TestNewRemoveCommandErrors(t *testing.T) { }{ { name: "wrong args", - expectedError: "requires at least 1 argument.", + expectedError: "requires at least 1 argument", }, { name: "ImageRemove fail with force option", diff --git a/cli/command/image/save_test.go b/cli/command/image/save_test.go index c6cff4cc3c22..dc64ebae9344 100644 --- a/cli/command/image/save_test.go +++ b/cli/command/image/save_test.go @@ -23,7 +23,7 @@ func TestNewSaveCommandErrors(t *testing.T) { { name: "wrong args", args: []string{}, - expectedError: "requires at least 1 argument.", + expectedError: "requires at least 1 argument", }, { name: "output to terminal", diff --git a/cli/command/image/tag_test.go b/cli/command/image/tag_test.go index 77bf81c2db6f..60e78b054fea 100644 --- a/cli/command/image/tag_test.go +++ b/cli/command/image/tag_test.go @@ -15,7 +15,7 @@ func TestCliNewTagCommandErrors(t *testing.T) { {"image1"}, {"image1", "image2", "image3"}, } - expectedError := "\"tag\" requires exactly 2 arguments." + expectedError := "\"tag\" requires 2 arguments" for _, args := range testCases { cmd := NewTagCommand(test.NewFakeCli(&fakeClient{})) cmd.SetArgs(args) diff --git a/cli/command/manifest/annotate_test.go b/cli/command/manifest/annotate_test.go index 089b29c71600..f2c924e45ffc 100644 --- a/cli/command/manifest/annotate_test.go +++ b/cli/command/manifest/annotate_test.go @@ -18,7 +18,7 @@ func TestManifestAnnotateError(t *testing.T) { }{ { args: []string{"too-few-arguments"}, - expectedError: "requires exactly 2 arguments", + expectedError: "requires 2 arguments", }, { args: []string{"th!si'sa/fa!ke/li$t/name", "example.com/alpine:3.0"}, diff --git a/cli/command/manifest/push_test.go b/cli/command/manifest/push_test.go index 2a11fceda2cf..a10d5b24db0c 100644 --- a/cli/command/manifest/push_test.go +++ b/cli/command/manifest/push_test.go @@ -31,7 +31,7 @@ func TestManifestPushErrors(t *testing.T) { }{ { args: []string{"one-arg", "extra-arg"}, - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { args: []string{"th!si'sa/fa!ke/li$t/-name"}, diff --git a/cli/command/network/connect_test.go b/cli/command/network/connect_test.go index cfdff2880605..c44fe3fc5f60 100644 --- a/cli/command/network/connect_test.go +++ b/cli/command/network/connect_test.go @@ -19,7 +19,7 @@ func TestNetworkConnectErrors(t *testing.T) { expectedError string }{ { - expectedError: "requires exactly 2 arguments", + expectedError: "requires 2 arguments", }, { args: []string{"toto", "titi"}, diff --git a/cli/command/network/create_test.go b/cli/command/network/create_test.go index 8eab2ff0bd81..348835f02ab4 100644 --- a/cli/command/network/create_test.go +++ b/cli/command/network/create_test.go @@ -21,7 +21,7 @@ func TestNetworkCreateErrors(t *testing.T) { expectedError string }{ { - expectedError: "exactly 1 argument", + expectedError: "1 argument", }, { args: []string{"toto"}, diff --git a/cli/command/network/disconnect_test.go b/cli/command/network/disconnect_test.go index bcbb491d096a..bb82452a6ce2 100644 --- a/cli/command/network/disconnect_test.go +++ b/cli/command/network/disconnect_test.go @@ -17,7 +17,7 @@ func TestNetworkDisconnectErrors(t *testing.T) { expectedError string }{ { - expectedError: "requires exactly 2 arguments", + expectedError: "requires 2 arguments", }, { args: []string{"toto", "titi"}, diff --git a/cli/command/node/update_test.go b/cli/command/node/update_test.go index 09881d7ec200..52e771a9ae9f 100644 --- a/cli/command/node/update_test.go +++ b/cli/command/node/update_test.go @@ -20,11 +20,11 @@ func TestNodeUpdateErrors(t *testing.T) { expectedError string }{ { - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { args: []string{"node1", "node2"}, - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { args: []string{"nodeID"}, diff --git a/cli/command/plugin/disable_test.go b/cli/command/plugin/disable_test.go index 40bfab72ea24..3920efa10133 100644 --- a/cli/command/plugin/disable_test.go +++ b/cli/command/plugin/disable_test.go @@ -19,11 +19,11 @@ func TestPluginDisableErrors(t *testing.T) { }{ { args: []string{}, - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { args: []string{"too", "many", "arguments"}, - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { args: []string{"plugin-foo"}, diff --git a/cli/command/plugin/enable_test.go b/cli/command/plugin/enable_test.go index 20fa25f74098..bb0861e6ce20 100644 --- a/cli/command/plugin/enable_test.go +++ b/cli/command/plugin/enable_test.go @@ -20,11 +20,11 @@ func TestPluginEnableErrors(t *testing.T) { }{ { args: []string{}, - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { args: []string{"too-many", "arguments"}, - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { args: []string{"plugin-foo"}, diff --git a/cli/command/secret/remove_test.go b/cli/command/secret/remove_test.go index 6b0dfcc2cdff..b5f4889a8cdf 100644 --- a/cli/command/secret/remove_test.go +++ b/cli/command/secret/remove_test.go @@ -20,7 +20,7 @@ func TestSecretRemoveErrors(t *testing.T) { }{ { args: []string{}, - expectedError: "requires at least 1 argument.", + expectedError: "requires at least 1 argument", }, { args: []string{"foo"}, diff --git a/cli/command/service/rollback_test.go b/cli/command/service/rollback_test.go index 742d9f99c404..28e7f27c6852 100644 --- a/cli/command/service/rollback_test.go +++ b/cli/command/service/rollback_test.go @@ -65,12 +65,12 @@ func TestRollbackWithErrors(t *testing.T) { }{ { name: "not-enough-args", - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { name: "too-many-args", args: []string{"service-id-1", "service-id-2"}, - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { name: "service-does-not-exists", diff --git a/cli/command/stack/ps_test.go b/cli/command/stack/ps_test.go index e14002e210a6..009d51ed8310 100644 --- a/cli/command/stack/ps_test.go +++ b/cli/command/stack/ps_test.go @@ -24,11 +24,11 @@ func TestStackPsErrors(t *testing.T) { }{ { args: []string{}, - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { args: []string{"foo", "bar"}, - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { args: []string{"foo"}, diff --git a/cli/command/swarm/join_test.go b/cli/command/swarm/join_test.go index 9a60e9e25e28..6d60d693d286 100644 --- a/cli/command/swarm/join_test.go +++ b/cli/command/swarm/join_test.go @@ -23,12 +23,12 @@ func TestSwarmJoinErrors(t *testing.T) { }{ { name: "not-enough-args", - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { name: "too-many-args", args: []string{"remote1", "remote2"}, - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { name: "join-failed", diff --git a/cli/command/swarm/join_token_test.go b/cli/command/swarm/join_token_test.go index 21b89e66529b..c97cc0012d16 100644 --- a/cli/command/swarm/join_token_test.go +++ b/cli/command/swarm/join_token_test.go @@ -27,12 +27,12 @@ func TestSwarmJoinTokenErrors(t *testing.T) { }{ { name: "not-enough-args", - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { name: "too-many-args", args: []string{"worker", "manager"}, - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { name: "invalid-args", diff --git a/cli/command/trust/key_generate_test.go b/cli/command/trust/key_generate_test.go index 9781a5338461..74fc3fed6891 100644 --- a/cli/command/trust/key_generate_test.go +++ b/cli/command/trust/key_generate_test.go @@ -26,12 +26,12 @@ func TestTrustKeyGenerateErrors(t *testing.T) { }{ { name: "not-enough-args", - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { name: "too-many-args", args: []string{"key-1", "key-2"}, - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, } diff --git a/cli/command/trust/key_load_test.go b/cli/command/trust/key_load_test.go index d32883fc6231..4d9e737e08e0 100644 --- a/cli/command/trust/key_load_test.go +++ b/cli/command/trust/key_load_test.go @@ -34,13 +34,14 @@ func TestTrustKeyLoadErrors(t *testing.T) { }{ { name: "not-enough-args", - expectedError: "exactly 1 argument", + expectedError: "1 argument", + args: []string{}, expectedOutput: "", }, { name: "too-many-args", args: []string{"iamnotakey", "alsonotakey"}, - expectedError: "exactly 1 argument", + expectedError: "1 argument", expectedOutput: "", }, { diff --git a/cli/command/trust/revoke_test.go b/cli/command/trust/revoke_test.go index 7521a7bcf266..6e2ebd66bfb6 100644 --- a/cli/command/trust/revoke_test.go +++ b/cli/command/trust/revoke_test.go @@ -24,12 +24,12 @@ func TestTrustRevokeCommandErrors(t *testing.T) { }{ { name: "not-enough-args", - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { name: "too-many-args", args: []string{"remote1", "remote2"}, - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { name: "sha-reference", diff --git a/cli/command/trust/sign_test.go b/cli/command/trust/sign_test.go index 8249ad893f41..7e8d0a08e70f 100644 --- a/cli/command/trust/sign_test.go +++ b/cli/command/trust/sign_test.go @@ -32,12 +32,12 @@ func TestTrustSignCommandErrors(t *testing.T) { }{ { name: "not-enough-args", - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { name: "too-many-args", args: []string{"image", "tag"}, - expectedError: "requires exactly 1 argument", + expectedError: "requires 1 argument", }, { name: "sha-reference", diff --git a/cli/required.go b/cli/required.go index ba4e6e8efa5e..8d01887d0fdb 100644 --- a/cli/required.go +++ b/cli/required.go @@ -22,11 +22,10 @@ func NoArgs(cmd *cobra.Command, args []string) error { } return errors.Errorf( - "%q accepts no arguments.\nSee '%s --help'.\n\nUsage: %s\n\n%s", - cmd.CommandPath(), + "%[1]s: '%[2]s' accepts no arguments\n\nUsage: %[3]s\n\nRun '%[2]s --help' for more information", + binName(cmd), cmd.CommandPath(), cmd.UseLine(), - cmd.Short, ) } @@ -37,13 +36,12 @@ func RequiresMinArgs(min int) cobra.PositionalArgs { return nil } return errors.Errorf( - "%q requires at least %d %s.\nSee '%s --help'.\n\nUsage: %s\n\n%s", + "%[1]s: '%[2]s' requires at least %[3]d %[4]s\n\nUsage: %[5]s\n\nSee '%[2]s --help' for more information", + binName(cmd), cmd.CommandPath(), min, pluralize("argument", min), - cmd.CommandPath(), cmd.UseLine(), - cmd.Short, ) } } @@ -55,13 +53,12 @@ func RequiresMaxArgs(max int) cobra.PositionalArgs { return nil } return errors.Errorf( - "%q requires at most %d %s.\nSee '%s --help'.\n\nUsage: %s\n\n%s", + "%[1]s: '%[2]s' requires at most %[3]d %[4]s\n\nUsage: %[5]s\n\nSRun '%[2]s --help' for more information", + binName(cmd), cmd.CommandPath(), max, pluralize("argument", max), - cmd.CommandPath(), cmd.UseLine(), - cmd.Short, ) } } @@ -73,14 +70,13 @@ func RequiresRangeArgs(min int, max int) cobra.PositionalArgs { return nil } return errors.Errorf( - "%q requires at least %d and at most %d %s.\nSee '%s --help'.\n\nUsage: %s\n\n%s", + "%[1]s: '%[2]s' requires at least %[3]d and at most %[4]d %[5]s\n\nUsage: %[6]s\n\nRun '%[2]s --help' for more information", + binName(cmd), cmd.CommandPath(), min, max, pluralize("argument", max), - cmd.CommandPath(), cmd.UseLine(), - cmd.Short, ) } } @@ -92,13 +88,12 @@ func ExactArgs(number int) cobra.PositionalArgs { return nil } return errors.Errorf( - "%q requires exactly %d %s.\nSee '%s --help'.\n\nUsage: %s\n\n%s", + "%[1]s: '%[2]s' requires %[3]d %[4]s\n\nUsage: %[5]s\n\nRun '%[2]s --help' for more information", + binName(cmd), cmd.CommandPath(), number, pluralize("argument", number), - cmd.CommandPath(), cmd.UseLine(), - cmd.Short, ) } } diff --git a/cli/required_test.go b/cli/required_test.go index 9c5fc0b0c8b4..795fb4589a77 100644 --- a/cli/required_test.go +++ b/cli/required_test.go @@ -18,7 +18,7 @@ func TestRequiresNoArgs(t *testing.T) { { args: []string{"foo"}, validateFunc: NoArgs, - expectedError: "accepts no arguments.", + expectedError: "accepts no arguments", }, } for _, tc := range testCases { @@ -36,12 +36,12 @@ func TestRequiresMinArgs(t *testing.T) { }, { validateFunc: RequiresMinArgs(1), - expectedError: "at least 1 argument.", + expectedError: "at least 1 argument", }, { args: []string{"foo"}, validateFunc: RequiresMinArgs(2), - expectedError: "at least 2 arguments.", + expectedError: "at least 2 arguments", }, } for _, tc := range testCases { @@ -60,12 +60,12 @@ func TestRequiresMaxArgs(t *testing.T) { { args: []string{"foo", "bar"}, validateFunc: RequiresMaxArgs(1), - expectedError: "at most 1 argument.", + expectedError: "at most 1 argument", }, { args: []string{"foo", "bar", "baz"}, validateFunc: RequiresMaxArgs(2), - expectedError: "at most 2 arguments.", + expectedError: "at most 2 arguments", }, } for _, tc := range testCases { @@ -88,12 +88,12 @@ func TestRequiresRangeArgs(t *testing.T) { { args: []string{"foo", "bar"}, validateFunc: RequiresRangeArgs(0, 1), - expectedError: "at most 1 argument.", + expectedError: "at most 1 argument", }, { args: []string{"foo", "bar", "baz"}, validateFunc: RequiresRangeArgs(0, 2), - expectedError: "at most 2 arguments.", + expectedError: "at most 2 arguments", }, { validateFunc: RequiresRangeArgs(1, 2), @@ -115,11 +115,11 @@ func TestExactArgs(t *testing.T) { }, { validateFunc: ExactArgs(1), - expectedError: "exactly 1 argument.", + expectedError: "1 argument", }, { validateFunc: ExactArgs(2), - expectedError: "exactly 2 arguments.", + expectedError: "2 arguments", }, } for _, tc := range testCases { diff --git a/cmd/docker/docker_test.go b/cmd/docker/docker_test.go index 84ea272a20ec..1998b77c9904 100644 --- a/cmd/docker/docker_test.go +++ b/cmd/docker/docker_test.go @@ -66,7 +66,7 @@ func TestExitStatusForInvalidSubcommandWithHelpFlag(t *testing.T) { func TestExitStatusForInvalidSubcommand(t *testing.T) { err := runCliCommand(t, nil, nil, "invalid") - assert.Check(t, is.ErrorContains(err, "docker: 'docker invalid' is not a docker command.")) + assert.Check(t, is.ErrorContains(err, "docker: unknown command: docker invalid")) } func TestVersion(t *testing.T) { diff --git a/e2e/cli-plugins/flags_test.go b/e2e/cli-plugins/flags_test.go index 836af32e2a9e..c4e5fbcbc408 100644 --- a/e2e/cli-plugins/flags_test.go +++ b/e2e/cli-plugins/flags_test.go @@ -180,14 +180,14 @@ func TestCliPluginsVersion(t *testing.T) { args: []string{"version", "foo"}, expCode: 1, expOut: icmd.None, - expErr: `"docker version" accepts no arguments.`, + expErr: `docker: 'docker version' accepts no arguments`, }, { name: "global-with-plugin-arg", args: []string{"version", "helloworld"}, expCode: 1, expOut: icmd.None, - expErr: `"docker version" accepts no arguments.`, + expErr: `docker: 'docker version' accepts no arguments`, }, { name: "global-version-flag-with-unknown-arg",