DisableFlagParsing must trigger custom completion for flag names#1161
DisableFlagParsing must trigger custom completion for flag names#1161jpmcb merged 1 commit intospf13:masterfrom
Conversation
b1f5abe to
906c1f3
Compare
|
Ref and possible conflict: #841. |
906c1f3 to
365fa40
Compare
|
After thinking about it further, especially in the context of persistent flags, I took a more flexible and less intrusive approach. If |
|
Let me give a little more context for this fix. Helm supports plugins. Each plugin is registered as a Cobra command. However, plugin sub-commands and plugin flags are not known to Helm/Cobra; they are handled directly by the plugin when it is executed. Therefore each plugin command has Cobra not knowing about plugin flags implies it cannot perform flag-name completion. We must instead request the completion from the plugin itself and the best way to do that is through This fix simply teaches Cobra to call A really cool scenario is then possible. For example, Helm has a plugin written using Cobra (helm-2to3). |
|
Oh and since there are whispers about a new release of Cobra, maybe this fix can sneak in before? |
365fa40 to
95fa4bc
Compare
95fa4bc to
f895c67
Compare
|
Please see description of the PR for a test program and testing steps. |
|
This PR is being marked as stale due to a long period of inactivity |
|
Waiting for review. |
0043ab7 to
cb96e4a
Compare
ca82f3b to
1341d6f
Compare
1341d6f to
571c9e1
Compare
When a command has set DisableFlagParsing=true, it means Cobra should not be handling flags for that command but should let the command handle them itself. In fact, Cobra normally won't have been told at all about flags for this command. Not knowing about the flags of the command also implies that Cobra cannot perform flag completion as it does not have the necessary info. This commit still tries to do flag name completion, but when DisableFlagParsing==true, it continues on so that ValidArgsFunction will be called; this allows the program to handle completion for its own flags when DisableFlagParsing==true. Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
571c9e1 to
cae6c02
Compare
|
The diff looks much bigger than it really is because of indentation changes. If we ignore the indentation changes there are less than 20 lines of changes (if we ignore the test). |
|
This is definitely something we want.
Can you elaborate on this @marckhouzam? Not sure I fully understand whats missing from this if we add in the calling of |
Sorry @jpmcb, my comment was confusing. I meant to say that the missing part in Cobra right now (before this PR) is the calling of So the PR is complete and ready. |
jpmcb
left a comment
There was a problem hiding this comment.
This is looking good! Let's get it in!
Did you mean to merge this @jpmcb or are you waiting for something from my side? |
|
My bad, should have merged this earlier - lost some context on this but looks like it's good to go in |
This version includes spf13/cobra#1161 which fixes an issue where completion options are not offered for plugin flags. Signed-off-by: Scott Andrews <andrewssc@vmware.com>
This version includes spf13/cobra#1161 which fixes an issue where completion options are not offered for plugin flags. Signed-off-by: Scott Andrews <andrewssc@vmware.com>
This version includes spf13/cobra#1161 which fixes an issue where completion options are not offered for plugin flags. Signed-off-by: Scott Andrews <andrewssc@vmware.com>
This version includes spf13/cobra#1161 which fixes an issue where completion options are not offered for plugin flags. Signed-off-by: Scott Andrews <andrewssc@vmware.com>
This version includes spf13/cobra#1161 which fixes an issue where completion options are not offered for plugin flags. Signed-off-by: Scott Andrews <andrewssc@vmware.com>
Closes #1160
When a command has set
DisableFlagParsing=true, it means Cobra should not be handling flags for that command but should let the command handle them itself. In fact, Cobra normally won't have been told at all about flags for this command.Not knowing about the flags of the command also implies that Cobra cannot perform flag completion as it does not have the necessary info.
When
DisableFlagParsing==truethis commit makes sureValidArgsFunctionwill be called even for flag name completion, which will allow the program to handle completion for its own flags in that case.Here is a program to test this:
then for bash
The same test can be run for
zshandfish, which both use a the Go completions (so a different code path than bash).