Skip to content

Commit 2b4fd0d

Browse files
committed
cmd/docker: setFlagErrorFunc: don't load plugins for invalid flags
On Docker CLI versions before v28.0.0, using an unknown flag would print the usage output, showing all available top-level flags and commands; docker --badopt unknown flag: --badopt See 'docker --help'. Usage: docker [OPTIONS] COMMAND A self-sufficient runtime for containers Options: --config string Location of client config files (default "/root/.docker") ... This output did not include plugin-commands, making the usage output incomplete. That issue was fixed in [cli@40a6cf7], which loaded all available cli-plugins, so that a stub was created for printing the plugin commands in the usage output. Similarly, [cli@79a75da] added code to hide experimental commands and commands not supported by the daemon. However, since 28.0.0 (commit [cli@f28fc7f]), the usage output was removed for this error, so loading plugins is no longer needed; docker --badopt unknown flag: --badopt Usage: docker [OPTIONS] COMMAND [ARG...] Run 'docker --help' for more information This patch removes the code added in [cli@40a6cf7] and [cli@79a75da]. With this patch, the output is still the same; docker --unknown-flag buildx ls --no-such unknown flag: --unknown-flag Usage: docker [OPTIONS] COMMAND [ARG...] Run 'docker --help' for more information This function only handles flags defined by the CLI itself; invalid flags for plugins are handled by the plugin itself, so are not impacted; docker buildx ls --no-such unknown flag: --no-such Usage: docker buildx ls Run 'docker buildx ls --help' for more information [cli@f28fc7f]: f28fc7f [cli@40a6cf7]: 40a6cf7 [cli@79a75da]: 79a75da Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 9c79528 commit 2b4fd0d

File tree

1 file changed

+0
-6
lines changed

1 file changed

+0
-6
lines changed

cmd/docker/docker.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,9 @@ func setFlagErrorFunc(dockerCli command.Cli, cmd *cobra.Command) {
181181
// is called.
182182
flagErrorFunc := cmd.FlagErrorFunc()
183183
cmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
184-
if err := pluginmanager.AddPluginCommandStubs(dockerCli, cmd.Root()); err != nil {
185-
return err
186-
}
187184
if err := isSupported(cmd, dockerCli); err != nil {
188185
return err
189186
}
190-
if err := hideUnsupportedFeatures(cmd, dockerCli); err != nil {
191-
return err
192-
}
193187
return flagErrorFunc(cmd, err)
194188
})
195189
}

0 commit comments

Comments
 (0)