-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include --help and --version flag in completion #1813
Conversation
718c5bc
to
8502dce
Compare
I realized that the completion logic for this improvement is still lacking. For example: I will need to treat the I will post an updated version soon. |
Nice! This all sounds good - give me a ping once this is ready to review! :D |
8502dce
to
a9841a3
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size. |
Fixes spf13#1786 The --help, -h, --version and -v flags are normally added when the `execute()` function is called on a command. When doing completion we don't call `execute()` so we need to add these flags explicitly to the command being completed. Also, we disable all further completions if the 'help' or 'version' flags are present on the command-line. Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>
a9841a3
to
ccb45fb
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size. |
Alright, this is ready @jpmcb. If you ignore the 234 lines of new tests, the change is fairly straightforward (< 30 lines). One important aspect that you may have a different opinion on is that I have added a new flag annotation: What to look for when testing (any generic test program will do):
Also the tests of the cobra-completion-testing repo all pass. |
Fixes #1786 The --help, -h, --version and -v flags are normally added when the `execute()` function is called on a command. When doing completion we don't call `execute()` so we need to add these flags explicitly to the command being completed. Also, we disable all further completions if the 'help' or 'version' flags are present on the command-line. Merge spf13/cobra#1813
Fixes #1786
Thanks to @fnickels's nice work on #1707, I realized why the
--help
/-h
and--version
/-v
flags where not included in shell completions.The
--help
,-h
,--version
and-v
flags are normally added when theexecute()
function is called on a command. When doing completion we don't callexecute()
so we need to add these flags explicitly to the command being completed.Also, when doing shell completion following those flags, this PR disables all completions.
To do so, we keep track of if the
--help
and--version
flags were added by Cobra using a new flag annotation.To test: