-
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
complete aliases for subcommands #1856
base: main
Are you sure you want to change the base?
Conversation
When completing a subcommand, also take its aliases into consideration instead of only its name. fixes spf13#1852
This look reasonable. The important thing is to avoid aliases coming in the way of other completions. Thanks @Airblader for the contribution. |
The Cobra project currently lacks enough contributors to adequately respond to all PRs. This bot triages issues and PRs according to the following rules:
|
Sorry for the long delay @Airblader. I finally got back to this.
Notice that the choices starting with the letter
Now the completion does not complete An alternative would be to only complete command aliases if no other completions are available.
This might be less surprising for a user. What do you think? Lines 450 to 458 in e839bb3
|
I sent that last comment too early, so I have edited it to add an example of the suggestion. |
Thanks for getting back! I see your point. Mh. This is a tricky one. There are two ways to use completions: as a visual list to look at and explore (as you did here), and for mindless tab-completion when you already know the command you're looking for and just want to save yourself keystrokes. Essentially either solution is good at one, but bad at the other. That said, the solution you propose does also make it difficult to discover potential aliases through completions, because completing "r" would instantly complete to "role", and the user would never learn about resourcequota. A third solution would be to just always provide all completions, even for all aliases. I'd argue this is the "technically correct" solution, but I imagine you wouldn't like this one very much? |
That would be always correct, indeed. But as you expected I feel it would reduce the user experience. It would possibly add a whole bunch of new completions to some already large list of choices. I'm a big fan of using the shell completion for discovery. However, I’m not sure we can use shell completion to help discover aliases without also reducing the user experience. I feel like aliases should not be in the way of the normal shell completion. They should just be considered if they don’t add noise. We can imagine that there can be many aliases for one command that would create noise if we showed them unilaterally. That’s why I’m thinking that if we do want to consider aliases, we would need to do them only if there are no other completions found. But this discussion shows that maybe showing aliases altogether is not something we should do, which is maybe why it was never done before. What do you think? |
My concern (and motivation for this PR) isn't so much showing the aliases, but offering the tab completion for them. I do feel strongly that not offering aliases to be completed is more of a usability issue than showing too many completions (personal opinion): why offer an alias at all if it is very awkward to use them? Since you brought up kubectl as an example, let me name another one that mirrors more closely where this PR is coming from. It's an internal tool similar to minikube, where there is a "pause" command aliased with "suspend" (and others, actually). Suspend might be the more intuitive verb for some users, but not being able to tab complete "sus" unfairly penalizes them with a worse experience. Yet another option here is to give control over this decision to the users of the library. Largely this may even already be achievable (haven't verified), though be a bit awkward to include in every command. A less flexible but easier to use solution would be some global configuration in Cobra. However I would also understand being hesitant to increase configuration surface. I do want to go on record and say that to me this isn't a minor usability topic, but a fundamental one. Tab completions is IMO one of the most impactful usability features in CLIs, and Cobra specifically has great support for it in general. 🙂 |
I'm in need for this for https://github.com/MichaelMure/git-bug. The current binary is named
This is the key point IMHO. No need to list every aliases, but having the completion react on them would be a great QOL improvement. |
When completing a subcommand, also take its aliases into consideration instead of only its name.
fixes #1852