mirror of https://github.com/docker/cli.git
Merge pull request #1850 from ijc/include-plugins-in-badopt-help
Include plugins in `docker --badopt` help output
This commit is contained in:
commit
245bfd15cd
|
@ -69,16 +69,22 @@ func newDockerCommand(dockerCli *command.DockerCli) *cli.TopLevelCommand {
|
|||
return cli.NewTopLevelCommand(cmd, dockerCli, opts, flags)
|
||||
}
|
||||
|
||||
func setFlagErrorFunc(dockerCli *command.DockerCli, cmd *cobra.Command) {
|
||||
func setFlagErrorFunc(dockerCli command.Cli, cmd *cobra.Command) {
|
||||
// When invoking `docker stack --nonsense`, we need to make sure FlagErrorFunc return appropriate
|
||||
// output if the feature is not supported.
|
||||
// As above cli.SetupRootCommand(cmd) have already setup the FlagErrorFunc, we will add a pre-check before the FlagErrorFunc
|
||||
// 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
|
||||
}
|
||||
if err := hideUnsupportedFeatures(cmd, dockerCli); err != nil {
|
||||
return err
|
||||
}
|
||||
return flagErrorFunc(cmd, err)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -74,18 +74,36 @@ func TestGlobalHelp(t *testing.T) {
|
|||
assert.Assert(t, is.Equal(badmetacount, 1))
|
||||
|
||||
// Running with `--help` should produce the same.
|
||||
res2 := icmd.RunCmd(run("--help"))
|
||||
res2.Assert(t, icmd.Expected{
|
||||
ExitCode: 0,
|
||||
t.Run("help_flag", func(t *testing.T) {
|
||||
res2 := icmd.RunCmd(run("--help"))
|
||||
res2.Assert(t, icmd.Expected{
|
||||
ExitCode: 0,
|
||||
})
|
||||
assert.Assert(t, is.Equal(res2.Stdout(), res.Stdout()))
|
||||
assert.Assert(t, is.Equal(res2.Stderr(), ""))
|
||||
})
|
||||
assert.Assert(t, is.Equal(res2.Stdout(), res.Stdout()))
|
||||
assert.Assert(t, is.Equal(res2.Stderr(), ""))
|
||||
|
||||
// Running just `docker` (without `help` nor `--help`) should produce the same thing, except on Stderr.
|
||||
res2 = icmd.RunCmd(run())
|
||||
res2.Assert(t, icmd.Expected{
|
||||
ExitCode: 0,
|
||||
t.Run("bare", func(t *testing.T) {
|
||||
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()))
|
||||
})
|
||||
|
||||
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))
|
||||
})
|
||||
assert.Assert(t, is.Equal(res2.Stdout(), ""))
|
||||
assert.Assert(t, is.Equal(res2.Stderr(), res.Stdout()))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue