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>
This commit is contained in:
Ian Campbell 2019-04-26 15:08:22 +01:00
parent 79a75da0fd
commit 40a6cf7c47
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.
flagErrorFunc := cmd.FlagErrorFunc()
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 {
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.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))
})
}