From c43da091888d6b2a427bab7b6c917107894ecbcd Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Tue, 22 Jan 2019 13:44:39 +0000 Subject: [PATCH] Add stubs when calling help due to no arguments e.g. the `docker` case which should act as `docker help`. Signed-off-by: Ian Campbell --- cmd/docker/docker.go | 20 +++++++++++--------- e2e/cli-plugins/help_test.go | 8 ++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index b9734453ff..d781b688ca 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -103,15 +103,6 @@ func setupHelpCommand(dockerCli *command.DockerCli, rootCmd, helpCmd *cobra.Comm return err } - // Add a stub entry for every plugin so they are - // included in the help output. If we have no args - // then this is being used for `docker help` and we - // want to include broken plugins, otherwise this is - // `help «foo»` and we do not. - if err := pluginmanager.AddPluginCommandStubs(dockerCli, rootCmd, len(args) == 0); err != nil { - return err - } - if origRunE != nil { return origRunE(c, args) } @@ -135,6 +126,17 @@ func setHelpFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *pflag. ccmd.Println(err) return } + + // Add a stub entry for every plugin so they are + // included in the help output. If we have no args + // then this is being used for `docker help` and we + // want to include broken plugins, otherwise this is + // `help «foo»` and we do not. + if err := pluginmanager.AddPluginCommandStubs(dockerCli, ccmd.Root(), len(args) == 0); err != nil { + ccmd.Println(err) + return + } + defaultHelpFunc(ccmd, args) }) } diff --git a/e2e/cli-plugins/help_test.go b/e2e/cli-plugins/help_test.go index c66dfacc0f..f9690fe503 100644 --- a/e2e/cli-plugins/help_test.go +++ b/e2e/cli-plugins/help_test.go @@ -51,4 +51,12 @@ func TestGlobalHelp(t *testing.T) { } assert.Assert(t, found, "Did not find match for %q in `docker help` output", expected) } + + // Running just `docker` (without help) should produce the same thing, except on Stderr + res2 := icmd.RunCmd(run()) + res2.Assert(t, icmd.Expected{ + ExitCode: 0, + }) + assert.Assert(t, is.Equal(res2.Stdout(), "")) + assert.Assert(t, is.Equal(res2.Stderr(), res.Stdout())) }