Ignore unknown arguments on the top-level command.
This allows passing argument to plugins, otherwise they are caught by the parse loop, since cobra does not know about each plugin at this stage (to avoid having to always scan for all plugins) this means that e.g. `docker plugin --foo` would accumulate `plugin` as an arg to the `docker` command, then choke on the unknown `--foo`. This allows unknown global args only, unknown arguments on subcommands (e.g. `docker ps --foo`) are still correctly caught. Add an e2e test covering this case. Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
@ -32,6 +32,16 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
TraverseChildren: true,
|
||||
FParseErrWhitelist: cobra.FParseErrWhitelist{
|
||||
// UnknownFlags ignores any unknown
|
||||
// --arguments on the top-level docker command
|
||||
// only. This is necessary to allow passing
|
||||
// --arguments to plugins otherwise
|
||||
// e.g. `docker plugin --foo` is caught here
|
||||
// in the monolithic CLI and `foo` is reported
|
||||
// as an unknown argument.
|
||||
UnknownFlags: true,
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 0 {
|
||||
return command.ShowHelp(dockerCli.Err())(cmd, args)
|
||||
|
||||
Reference in New Issue
Block a user