Skip to content

Commit 2e01bda

Browse files
author
Hernan Garcia
committed
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-<command name>`, 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 <hernandanielg@gmail.com> Signed-off-by: Hernan Garcia <hernan.garcia@percona.com>
1 parent dc2eb3b commit 2e01bda

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

cmd/docker/docker.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ func setHelpFunc(dockerCli command.Cli, cmd *cobra.Command) {
137137
return
138138
}
139139

140-
if len(args) >= 1 {
140+
// commands are chained in the form `rootCmd 1stCmd 2ndCmd...`
141+
// if RootCmd and ParentCmd are the same
142+
// then my command is 1st level command
143+
if len(args) >= 1 && ccmd.Root() == ccmd.Parent() {
141144
err := tryRunPluginHelp(dockerCli, ccmd, args)
142145
if err == nil {
143146
return

0 commit comments

Comments
 (0)