From 2e01bdae1b5f555c3665667b2b2fe3532d6716e0 Mon Sep 17 00:00:00 2001 From: Hernan Garcia Date: Thu, 6 Jul 2023 04:23:15 -0500 Subject: [PATCH] prevent `tryRunPluginHelp()` execution on non-1st-level commands. commands comes in the form of `rootCmd 1stCmd 2ndCmd` and the `tryRunPluginHelp()` function takes the command name to run plugin help in the form `docker-`, if command name matches a plugin name it will display the wrong help message. to make sure we're using 1stCmd level we check if the root command is the same as the command parent. e.g. `docker swarm init --help` ``` docker: is the root command swarm : 1st level command init : 2nd level command --help: is a flag ``` this approach is not taking in consideration if a plugin and 1st level command matches, for example `docker foo` command and `docker-foo` plugin. Signed-off-by: Hernan Garcia Signed-off-by: Hernan Garcia --- cmd/docker/docker.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index 30c48b40d1..e0c84f73a9 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -137,7 +137,10 @@ func setHelpFunc(dockerCli command.Cli, cmd *cobra.Command) { return } - if len(args) >= 1 { + // commands are chained in the form `rootCmd 1stCmd 2ndCmd...` + // if RootCmd and ParentCmd are the same + // then my command is 1st level command + if len(args) >= 1 && ccmd.Root() == ccmd.Parent() { err := tryRunPluginHelp(dockerCli, ccmd, args) if err == nil { return