Skip to content

add autocomplete descriptions for aliases and extensions#5447

Merged
samcoe merged 5 commits intocli:trunkfrom
rpadaki:alias-extension-completion-desc
Apr 26, 2022
Merged

add autocomplete descriptions for aliases and extensions#5447
samcoe merged 5 commits intocli:trunkfrom
rpadaki:alias-extension-completion-desc

Conversation

@rpadaki
Copy link
Copy Markdown
Contributor

@rpadaki rpadaki commented Apr 12, 2022

This is another tiny fix, but solves a headache I've been running into. Cobra supports nice descriptions for shell completions, even if specified via a ValidArgsFunction -- simply append the description to the argument, separated by \t.

In this PR, I give aliases the description "Alias for CMD", and give extensions the description "Extension REPO/URL, version VERSION".

For example, my zsh autocompletion now contains the entries:

...
clone        -- Alias for repo clone
co           -- Alias for pr checkout
...
repo-rename  -- Extension crguezl/gh-repo-rename, version 5a47360e8bfcf9047b

Obviously, we can tinker with/format these descriptions as needed -- I tried to match git's alias autocompletion behavior for aliases and made this description up for extensions.

Additionally, once the descriptions are added, Cobra automatically sorts the commands into the full commands list!

@rpadaki rpadaki requested a review from a team as a code owner April 12, 2022 23:01
@rpadaki rpadaki requested review from samcoe and removed request for a team April 12, 2022 23:01
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Apr 12, 2022
@samcoe samcoe self-assigned this Apr 13, 2022
Copy link
Copy Markdown
Contributor

@samcoe samcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpadaki Thanks for the contribution. The code looks good to me. I added a commit to properly handle the local extension case since they will not have URLs to parse.

@mislav What do you think about using the alias definition as the description?

mislav
mislav previously requested changes Apr 25, 2022
Copy link
Copy Markdown
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making our completions better! I have some asks before this is ready to be merged

@samcoe samcoe requested a review from mislav April 26, 2022 07:44
@samcoe samcoe dismissed mislav’s stale review April 26, 2022 11:08

Addressed feedback.

@samcoe samcoe merged commit 7a3d02d into cli:trunk Apr 26, 2022
@rpadaki rpadaki deleted the alias-extension-completion-desc branch April 30, 2022 02:51
@rpadaki
Copy link
Copy Markdown
Contributor Author

rpadaki commented Apr 30, 2022

Thanks for taking care of the comments @samcoe! I unfortunately got pretty sick this week from you-know-what, so I really wasn't able to help out much T.T

@mislav
Copy link
Copy Markdown
Contributor

mislav commented May 1, 2022

@rpadaki That is perfectly fine; I hope you recovered well by now! Thank you @samcoe for seeing this to completion 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zsh autocompletion menu sometimes includes stray "co"

4 participants