Skip to content
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

add shell completions #1166

Open
Tony-Sol opened this issue Feb 10, 2023 · 8 comments
Open

add shell completions #1166

Tony-Sol opened this issue Feb 10, 2023 · 8 comments

Comments

@Tony-Sol
Copy link
Contributor

Is there a way to add shell completion for brew bundle command?

@MikeMcQuaid
Copy link
Member

Yes, completions could be added into completions/{bash,zsh,fish} directories in this tap.

@MikeMcQuaid MikeMcQuaid changed the title a completion function is not defined for command or alias: bundle add shell competions Feb 10, 2023
@MikeMcQuaid MikeMcQuaid changed the title add shell competions add shell completions Feb 10, 2023
@Homebrew Homebrew deleted a comment from clogin Aug 24, 2023
@superatomic
Copy link

I have experience with writing fish shell completion and I would be willing to do so. Unfortunately, I have never written completion for bash or zsh.

@MikeMcQuaid
Copy link
Member

@superatomic Thanks for the offer! I think the ideal for all three types of completions would be to use the Homebrew::Completions module in Homebrew/brew to generate them for taps like this based on the existing commands. Happy to help walk you through as much of that as possible but feel free to "nope" if that seems like too heavy a lift!

@rrotter
Copy link
Contributor

rrotter commented Apr 13, 2024

Took a stab at this and the issue I'm seeing with Homebrew::Completions is that it has minimal support for subcommands of subcommands (I'll refer to these as "sub-subcommands" from here out for clarity): there is no support for printing help text for sub-subcommands or allowing different flags for each sub-subcommand (both of which would be difficult to add there [in Homebrew::Completions] because Homebrew::AbstractCommand lacks a framework to encode these data).

I understand the preference for automatically generating completions in CI, as expressed in your comment on #1216; would you consider a PR that automates completion generation but doesn't use Homebrew::Completions? Otherwise I suspect that this issue can't be completed without changes in https://github.com/homebrew/brew to Homebrew::Completions and possibly Homebrew::AbstractCommand to support sub-subcommand help text.

At a minimum it would be easy enough to make an erb template based on #1216 and fill in the flag help text using Homebrew::CLI::Parser.from_cmd_path( Commands.path('bundle') ).processed_options (or perhaps an existing helper method in Homebrew::CLI::Parser or Commands if there is a better way to extract that data) Commands.command_options('bundle').

@Tony-Sol
Copy link
Contributor Author

i believe that there is more complicated way - both and automatically generating completions in CI AND usage of Homebrew::Completions module: at first you need to register all possible command with their descriptions in module, then run shell script generation.

But yeah, i didn't finish this cause lack of free time exactly to deal with Homebrew::Completions module 😢

@MikeMcQuaid
Copy link
Member

Took a stab at this and the issue I'm seeing with Homebrew::Completions is that it has minimal support for subcommands of subcommands (I'll refer to these as "sub-subcommands" from here out for clarity): there is no support for printing help text for sub-subcommands or allowing different flags for each sub-subcommand (both of which would be difficult to add there [in Homebrew::Completions] because Homebrew::AbstractCommand lacks a framework to encode these data).

@dduugg ☝🏻 as you might find this an interesting area for potential extension or improvement.

I understand the preference for automatically generating completions in CI, as expressed in your comment on #1216; would you consider a PR that automates completion generation but doesn't use Homebrew::Completions?

This would be more likely to be accepted than anything manual, yeh, particularly if this CI breaks if you add commands and forget to add completions.

Otherwise I suspect that this issue can't be completed without changes in homebrew/brew to Homebrew::Completions and possibly Homebrew::AbstractCommand to support sub-subcommand help text.

Improving the Homebrew/brew support here feels more desirable if possible (and @dduugg may be able to do or help with this).

@dduugg
Copy link
Sponsor Member

dduugg commented Apr 21, 2024

Sorry, just catching up on this mention, @MikeMcQuaid. Could I trouble you for concrete examples of sub-commands to help me form a mental model? (Might be useful to do a quick sync on the topic if we can find the time.)

I think if I were to sink another large chunk of time into this space, I would work on proper namespaces for Args (they're currently all in the same namespace - you could reference an arg from the wrong command and sorbet wouldn't notice the problem), but I'm open to other suggestions.

@MikeMcQuaid
Copy link
Member

Could I trouble you for concrete examples of sub-commands to help me form a mental model?

@dduugg brew bundle exec or brew services list would be examples of subcommands i.e. an additional noun/verb beyond a command which has its own flags/etc.

That make sense?

I would work on proper namespaces for Args

Yeh, this also feels like a nice thing do consider 👍🏻

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

No branches or pull requests

5 participants