Include CLI plugins in help output on unknown flag.

Previously `docker --badopt` output would not include CLI plugins.

Fixes #1813

Signed-off-by: Ian Campbell <ijc@docker.com>
(cherry picked from commit 40a6cf7c47)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Ian Campbell 2019-04-26 15:08:22 +01:00 committed by Sebastiaan van Stijn
parent 6a6cd35985
commit 7380aae601
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 17 additions and 0 deletions

View File

@ -76,6 +76,9 @@ func setFlagErrorFunc(dockerCli *command.DockerCli, cmd *cobra.Command) {
// is called. // is called.
flagErrorFunc := cmd.FlagErrorFunc() flagErrorFunc := cmd.FlagErrorFunc()
cmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error { cmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
if err := pluginmanager.AddPluginCommandStubs(dockerCli, cmd.Root()); err != nil {
return err
}
if err := isSupported(cmd, dockerCli); err != nil { if err := isSupported(cmd, dockerCli); err != nil {
return err return err
} }

View File

@ -92,4 +92,18 @@ func TestGlobalHelp(t *testing.T) {
assert.Assert(t, is.Equal(res2.Stdout(), "")) assert.Assert(t, is.Equal(res2.Stdout(), ""))
assert.Assert(t, is.Equal(res2.Stderr(), res.Stdout())) assert.Assert(t, is.Equal(res2.Stderr(), res.Stdout()))
}) })
t.Run("badopt", func(t *testing.T) {
// Running `docker --badopt` should also produce the
// same thing, give or take the leading error message
// and a trailing carriage return (due to main() using
// Println in the error case).
res2 := icmd.RunCmd(run("--badopt"))
res2.Assert(t, icmd.Expected{
ExitCode: 125,
})
assert.Assert(t, is.Equal(res2.Stdout(), ""))
exp := "unknown flag: --badopt\nSee 'docker --help'.\n" + res.Stdout() + "\n"
assert.Assert(t, is.Equal(res2.Stderr(), exp))
})
} }