-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Subcommand aliases not included in completion scripts #4265
Comments
We've had some back and forth on whether things that are hidden from help should show up in completions
When we resolve #3166, my thought is to handle this according to #3951 |
That makes sense, but it doesn't seem to affect the completion script. Are you open to a PR to add visible aliases to the completion scripts if I can figure out how? |
I've noticed a few other bugs while working on this. Do you prefer that I file separate bugs for those? Looking at past release notes, it doesn't look like you require a bug for each fix, but I don't mind creating them if you prefer. |
Separate issues are good in case
I would at least ask for separate commits for each one. If a change is likely to have more discussion, having that in a separate PR helps. |
This continues the work started with the fix for clap-rs#4273. There was another bug caused by using the subcommand names without considering their position in the argument list. If the user enters `git diff log <TAB>`, we build up a string that identifies the subcommand. We ended up making the string `git__diff__log` in this case because we appended `__log` without considering the current state. Since `git__diff__log` does not correspond to an actual command, we wouldn't provide any suggestions. This commit restructures the code so we walk subcommands and subsubcommands in `bash.rs`. While walking those, we build up a list containing triples of the parent `$cmd` name (e.g. `git__diff`), the current command's name (e.g. `log`), and the `$cmd` for the current command. We then build the shell script's case arms based on that information. We could instead have fixed clap-rs#4280 by using the second element in the pair returned from `utils::all_subcommands()` (a stringified list of the subcommand path) instead of the first one. However, that would not have helped us solve clap-rs#4265. Closes clap-rs#4280
With the previous fixes for clap-rs#4273 and clap-rs#4280 in place, it's now easy to add support for subcommand aliases, which this commit does. This addresses clap-rs#4265 for Bash.
This continues the work started with the fix for clap-rs#4273. There was another bug caused by using the subcommand names without considering their position in the argument list. If the user enters `git diff log <TAB>`, we build up a string that identifies the subcommand. We ended up making the string `git__diff__log` in this case because we appended `__log` without considering the current state. Since `git__diff__log` does not correspond to an actual command, we wouldn't provide any suggestions. This commit restructures the code so we walk subcommands and subsubcommands in `bash.rs`. While walking those, we build up a list containing triples of the parent `$cmd` name (e.g. `git__diff`), the current command's name (e.g. `log`), and the `$cmd` for the current command. We then build the shell script's case arms based on that information. We could instead have fixed clap-rs#4280 by using the second element in the pair returned from `utils::all_subcommands()` (a stringified list of the subcommand path) instead of the first one. However, that would not have helped us solve clap-rs#4265. Closes clap-rs#4280
With the previous fixes for clap-rs#4273 and clap-rs#4280 in place, it's now easy to add support for subcommand aliases, which this commit does. This addresses clap-rs#4265 for Bash.
This continues the work started with the fix for clap-rs#4273. There was another bug caused by using the subcommand names without considering their position in the argument list. If the user enters `git diff log <TAB>`, we build up a string that identifies the subcommand. We ended up making the string `git__diff__log` in this case because we appended `__log` without considering the current state. Since `git__diff__log` does not correspond to an actual command, we wouldn't provide any suggestions. This commit restructures the code so we walk subcommands and subsubcommands in `bash.rs`. While walking those, we build up a list containing triples of the parent `$cmd` name (e.g. `git__diff`), the current command's name (e.g. `log`), and the `$cmd` for the current command. We then build the shell script's case arms based on that information. We could instead have fixed clap-rs#4280 by using the second element in the pair returned from `utils::all_subcommands()` (a stringified list of the subcommand path) instead of the first one. However, that would not have helped us solve clap-rs#4265. Closes clap-rs#4280
With the previous fixes for clap-rs#4273 and clap-rs#4280 in place, it's now easy to add support for subcommand aliases, which this commit does. This addresses clap-rs#4265 for Bash.
Although the zsh completion supports listing the aliases for |
Please complete the following tasks
Rust Version
1.63.0
Clap Version
3.2.22
Minimal reproducible code
Steps to reproduce the bug with the above code
Run the program to print out a completion script for Bash
Actual Behaviour
Sourcing the completion script and then running
test <TAB>
will not suggestbar
andtest bar <TAB>
will not suggest--my-flag
.Expected Behaviour
test bar <TAB>
should suggest--my-flag
. I'm not sure if I thinktest <TAB>
should suggest bothfoo
andbar
; perhaps the current behavior of not suggesting aliases is best?The same bug exists in the Fish completion script. I haven't tried others (or checked the code).
I actually noticed the bug because my tool has
jj log
command and ajj operation/op log
command, and I ranjj op log <TAB>
, which suggested arguments that are forjj log
. That's because theop
(an alias foroperation
) is ignored and completion is run forjj log
instead.Additional Context
No response
Debug Output
No response
The text was updated successfully, but these errors were encountered: