docker swarm init: fix help printing#4403
Conversation
481b63a to
7648510
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #4403 +/- ##
=======================================
Coverage 61.05% 61.05%
=======================================
Files 295 295
Lines 20647 20647
=======================================
Hits 12605 12605
Misses 7146 7146
Partials 896 896 |
| } | ||
|
|
||
| if len(args) >= 1 { | ||
| if len(args) >= 1 && ccmd.Root() == ccmd.Parent() { |
There was a problem hiding this comment.
Thank you for working on this!!
I'm slightly trying to get my head around the fix; and probably it could need a comment in the code, describing what we're doing here, and a similar comment in the commit message.
Also (not yet fully grasping the fix 😓 , so perhaps silly question); this only takes .Parent() into account, does that affect cases where "nested" commands could run into this?
There was a problem hiding this comment.
Hey! 👋🏻 I enjoyed working on this one, even tho it's an easy fix I struggled to make dlv debugger to work in vscode and then to find the issue, but it was fun
So yeah I know, I need to add comments and maybe do it in a better way like create a function that does the check and returns a boolean
The idea is to identify if the command is first level command, in the case of docker swarm init --help
docker: is the root command
swarm : 1st level command
init : 2nd level command
--help: is a flag
Why to idenfity 1st only? because docker plugins are in the form docker-<plugin name>, for this reason it was taking 2nd command init and making it docker-init
So how do we identify if it's the 1st level? checking parent command and root command, if both are the same then my command it's 1st level command - in the init case, root cmd is docker and parent is swarm so it will fail, no need to check great parent or nested
Yeah definitely will improve the commit, this was my first shot - thanks for the review!
There was a problem hiding this comment.
(quick comment, in a call right now)
and maybe do it in a better way like create a function that does the check and returns a boolean
I'm fine with keeping the code in-line. Abstracting things can also hide logic, and sometimes it's fine to just have the logic in plain sight (not "shoved under the rug" to hide it away)
There was a problem hiding this comment.
added comments and rewrote commit msg, any help with wording will be highly appreciated 🙏🏻
There was a problem hiding this comment.
Hello @thaJeztah changes has been performed, can this be reviewed again? 🙏🏻
7648510 to
00f09de
Compare
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>
00f09de to
2e01bda
Compare
| // 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() { |
There was a problem hiding this comment.
In my case, Parent is always nil, so this check is never true, making it effectively if false {
I haven't fully followed the whole code yet, but it looks to me like we can just explicitly delete that whole branch:
docker <plugin> ... --help will be forwarded to the plugin cli directly so it won't even be handled here.
docker help <plugin> is already handled by setupHelpCommand
Or are there any other ways to "call for help" that I'm not aware of?
There was a problem hiding this comment.
I think 2nd condition (the one I added) makes sense only if len(args) is > 1 , situations like docker foo bar so bar won't be considered to check if it's a plugin... but yeah I agree with you, maybe we can remove the whole thing, I'll make some tests and modify this PR (bear with me)
Signed-off-by: Hernan Garcia <hernandanielg@gmail.com>
20b1c55 to
b0cd429
Compare
fixes #4400
On the
setHelpFuncfunction it tries to execute plugins's helps at first based in the ammount of arguments, the help fordocker swarm init --helpwas getting matched withdocker-initplugin, thus printing pluging help to outputTo fix this we make sure that even thought we have 1 or more arguments it will check if the command it's first level of command by checking that the root command is the same as the parent command
- What I did
- How I did it
- How to verify it
docker buildx bakeswarm initcommand with--helpflag./build/docker swarm init --helpexpected output
- Description for the changelog
fix to prevent wrong help message for commands with same name than docker plugins
- A picture of a cute animal (not mandatory but encouraged)
