-
Notifications
You must be signed in to change notification settings - Fork 192
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
CLI: do not provide command hints during tab-completion #5012
CLI: do not provide command hints during tab-completion #5012
Conversation
The `verdi` command uses a custom `Group` subclass that overrides the `get_command` method to provide some additional information in case the provided command name does not exist. These hints should help the user spot potential typos by giving a list of existing commands with similar names. However, this feature was also being triggered during tab-completion. For example, typing `verdi comput list` followed by activating tab-completion would result in the error being displayed since `comput` is not a valid command. In this case, one does not want to display the error message with hint at all. The tricky part is that there is no canonical way to distinguish between a normal command execution and a tab-completion event. The best bet is to use the `resilient_parsing` attribute on the `Context` which is set to `True` during tab-completion. Although this attribute was introduced into `click` directly to support auto-completion functionality, the problem is that this is not the only use case for which this flag can be set. It is therefore possible that there is some code path where this flag is set to `True` but it does not actually correspond to a tab-completion event. For now there doesn't seem to be a better solution though and in most cases this approach should work.
Codecov Report
@@ Coverage Diff @@
## develop #5012 +/- ##
===========================================
+ Coverage 80.12% 80.12% +0.01%
===========================================
Files 515 515
Lines 36692 36694 +2
===========================================
+ Hits 29397 29399 +2
Misses 7295 7295
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think that's OK - as a note (for myself mostly), I tried and just returning will trigger the 'default' bash completion (files in the current folder). I think that's OK and in line with other codes.
Also, I think using resilient_parsing
is OK - maybe there are other places where this will be needed, but I think we're being more resilient than before with this change, so this should be good.
The `verdi` command uses a custom `Group` subclass that overrides the `get_command` method to provide some additional information in case the provided command name does not exist. These hints should help the user spot potential typos by giving a list of existing commands with similar names. However, this feature was also being triggered during tab-completion. For example, typing `verdi comput list` followed by activating tab-completion would result in the error being displayed since `comput` is not a valid command. In this case, one does not want to display the error message with hint at all. The tricky part is that there is no canonical way to distinguish between a normal command execution and a tab-completion event. The best bet is to use the `resilient_parsing` attribute on the `Context` which is set to `True` during tab-completion. Although this attribute was introduced into `click` directly to support auto-completion functionality, the problem is that this is not the only use case for which this flag can be set. It is therefore possible that there is some code path where this flag is set to `True` but it does not actually correspond to a tab-completion event. For now there doesn't seem to be a better solution though and in most cases this approach should work. Cherry-pick: 8e763bb
Fixes #3815
The
verdi
command uses a customGroup
subclass that overrides theget_command
method to provide some additional information in case theprovided command name does not exist. These hints should help the user
spot potential typos by giving a list of existing commands with similar
names.
However, this feature was also being triggered during tab-completion.
For example, typing
verdi comput list
followed by activatingtab-completion would result in the error being displayed since
comput
is not a valid command. In this case, one does not want to display the
error message with hint at all.
The tricky part is that there is no canonical way to distinguish between
a normal command execution and a tab-completion event. The best bet is
to use the
resilient_parsing
attribute on theContext
which is setto
True
during tab-completion. Although this attribute was introducedinto
click
directly to support auto-completion functionality, theproblem is that this is not the only use case for which this flag can be
set. It is therefore possible that there is some code path where this
flag is set to
True
but it does not actually correspond to atab-completion event. For now there doesn't seem to be a better solution
though and in most cases this approach should work.