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 <ijc@docker.com>
This commit is contained in:
Ian Campbell 2019-01-22 13:44:39 +00:00
parent f912b55bd1
commit c43da09188
2 changed files with 19 additions and 9 deletions

View File

@ -103,15 +103,6 @@ func setupHelpCommand(dockerCli *command.DockerCli, rootCmd, helpCmd *cobra.Comm
return err 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 { if origRunE != nil {
return origRunE(c, args) return origRunE(c, args)
} }
@ -135,6 +126,17 @@ func setHelpFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *pflag.
ccmd.Println(err) ccmd.Println(err)
return 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) defaultHelpFunc(ccmd, args)
}) })
} }

View File

@ -51,4 +51,12 @@ func TestGlobalHelp(t *testing.T) {
} }
assert.Assert(t, found, "Did not find match for %q in `docker help` output", expected) 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()))
} }