From 2b4fd0d7505b297515dda420212f71979c0ac3c4 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 30 Sep 2025 23:58:24 +0200 Subject: [PATCH 1/2] 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]: https://github.com/docker/cli/commit/f28fc7f82fc87d0ed521de452b6227cee76fd956 [cli@40a6cf7]: https://github.com/docker/cli/commit/40a6cf7c477cf328134b0b8dcdbd9a09d02f918b [cli@79a75da]: https://github.com/docker/cli/commit/79a75da0fd97b02311676028c3406b242c785f7c Signed-off-by: Sebastiaan van Stijn --- cmd/docker/docker.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index 7d58ee61555a..d1e056b9f35e 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -181,15 +181,9 @@ func setFlagErrorFunc(dockerCli command.Cli, 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 } - if err := hideUnsupportedFeatures(cmd, dockerCli); err != nil { - return err - } return flagErrorFunc(cmd, err) }) } From b0201c8531d2a1af66c1d52e02eeea571a941730 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 1 Oct 2025 01:57:59 +0200 Subject: [PATCH 2/2] cmd/docker: hideUnsupportedFeatures: remove unused error return ``` 70.72 cmd/docker/docker.go:560:74: hideUnsupportedFeatures - result 0 (error) is always nil (unparam) 70.72 func hideUnsupportedFeatures(cmd *cobra.Command, details versionDetails) error { 70.72 ^ 70.72 1 issues: ``` Signed-off-by: Sebastiaan van Stijn --- cmd/docker/docker.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index d1e056b9f35e..9846dc3f7f9b 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -254,10 +254,7 @@ func setHelpFunc(dockerCli command.Cli, cmd *cobra.Command) { ccmd.Println(err) return } - if err := hideUnsupportedFeatures(ccmd, dockerCli); err != nil { - ccmd.Println(err) - return - } + hideUnsupportedFeatures(ccmd, dockerCli) defaultHelpFunc(ccmd, args) }) @@ -557,7 +554,7 @@ func hideSubcommandIf(subcmd *cobra.Command, condition func(string) bool, annota } } -func hideUnsupportedFeatures(cmd *cobra.Command, details versionDetails) error { +func hideUnsupportedFeatures(cmd *cobra.Command, details versionDetails) { var ( notExperimental = func(_ string) bool { return !details.ServerInfo().HasExperimental } notOSType = func(v string) bool { return details.ServerInfo().OSType != "" && v != details.ServerInfo().OSType } @@ -613,7 +610,6 @@ func hideUnsupportedFeatures(cmd *cobra.Command, details versionDetails) error { hideSubcommandIf(subcmd, notSwarmStatus, "swarm") hideSubcommandIf(subcmd, versionOlderThan, "version") } - return nil } // Checks if a command or one of its ancestors is in the list