diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index f522a29a03..5b0fffb004 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -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 } diff --git a/e2e/cli-plugins/help_test.go b/e2e/cli-plugins/help_test.go index f023b0f2f1..b73054d4a3 100644 --- a/e2e/cli-plugins/help_test.go +++ b/e2e/cli-plugins/help_test.go @@ -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)) + }) }