mirror of https://github.com/docker/cli.git
cmd/docker: Check command exists before raising flag error
Signed-off-by: William North <billynorth10@gmail.com>
This commit is contained in:
parent
421e3b5e91
commit
33845a4d5d
|
@ -116,6 +116,15 @@ func setFlagErrorFunc(dockerCli command.Cli, cmd *cobra.Command) {
|
|||
// is called.
|
||||
flagErrorFunc := cmd.FlagErrorFunc()
|
||||
cmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
|
||||
// When TraverseChildren is set to true on a parent command,
|
||||
// Cobra will parse flags before looking for the appropriate command to run.
|
||||
// First check the command exists before raising a flag error
|
||||
args := os.Args[1:]
|
||||
commandExists := findCommand(cmd, args)
|
||||
|
||||
if !commandExists {
|
||||
return fmt.Errorf("docker: '%s' is not a docker command.\nSee 'docker --help'", args[0])
|
||||
}
|
||||
if err := pluginmanager.AddPluginCommandStubs(dockerCli, cmd.Root()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue