-
Notifications
You must be signed in to change notification settings - Fork 55
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 completion supported by clap #43
Conversation
Hey @DrSensor thanks for the PR! I'll review this week as I have some time off 👍 . |
Thanks again for this PR! It's awesome that clap has support for completions built-in. So i've been thinking about the I was thinking, maybe we do this Here's how the My thinking here is that root level options |
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.
See comment ^
Wow, would love to see this get merged <3 @DrSensor or @jakedeichert got a moment to take a look? Wish I knew any Rust so I could do it myself :D |
Ah, thanks @mrmurphy for bringing this up. I just realized there is one problem with this feature. It can't be added in the startup script ( e.g .config.fish or .bash_profile ). |
Ah okay, that would be a problem! |
Hmmm... wouldn't a user be able to do |
Well i guess i was assuming the user would run Though, I myself would probably make a helper function or alias in my bash_profile that would wrap In the original issue, jgroom posted a bash completions example which involved no changes to mask. I'm now wondering if we should just rely on community-supplied scripts that do simple parsing of the markdown headers for command names. I'd be very happy to link to these scripts (fish, bash, zsh, whatever) from the repo's readme. If we're unsure about this solution today, we can close this PR and revisit this in the future. Baking completions support into mask i'm indifferent about, currently. |
I actually in favor of community-supplied scripts though it has the downside that the user need to make sure some built-ins CLI like sed/grep are indeed sed/grep (or at least being aliased properly). mask --maskfile ~/global.md --completion bash subcmd subsubcmd ... which generates the completion-script on certain sub/subsub...command. Here I can see a use case when the user needs different auto-completion when opening certain IDE. Well, supporting both clap and community-supplied scripts is also an option 😄 |
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.
@DrSensor thanks for updating the PR and all the work you've done so far!
Unfortunately, I'm going to make the call here to reject this again 🙁
In your last comment, you mentioned that you can now get completions specifically on subcmds and subsubcmds:
mask --maskfile ~/global.md --completion bash subcmd subsubcmd ...
I personally don't think we need to go that far. I think it's an interesting idea, but I don't want to support the extra complexity this contains. I much prefer the simplicity of the user just running mask --maskfile ~/global.md --completion bash | source
or mask --completion bash | source
depending which mask context they're working in. I know i would be making shortcut aliases for these so it would automatically happen depending on which directory i'm in.
I see 2 ways forward from here:
- We make this PR dead simple and only add support for a
--completion sh
arg. No cmd filtering or other logic. - We close this PR and wait until clap v3 releases to see if they still have completion generation support built in. In the meantime, we link to community supplied scripts instead.
As we both know, mask is a very weird binary. It behaves completely differently based on your context and I'm worried that bundling completion generation now might not result in a great user experience 🙁
I choose option 2 then. It seems quite reasonable to wait for clap v3. In my last changes, it's weird that I need to call |
@@ -11,9 +11,9 @@ fn main() { | |||
let cli_app = App::new(crate_name!()) | |||
.setting(AppSettings::VersionlessSubcommands) | |||
.setting(AppSettings::AllowNegativeNumbers) | |||
.setting(AppSettings::SubcommandRequired) |
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.
Side note for future references.
Even without subcommand filtering,
AppSettings::{
SubcommandRequired
,
SubcommandRequiredElseHelp
}
still need to be disabled orunset_setting
Which issue does this fix?
Closes #18
Describe the solution
Inspired from starship [1], this PR will add
init
subcommand to generate shell completion viaclap
crate [2].[1] https://starship.rs/#quick-install (jump to step 2)
[2] https://docs.rs/clap/2.33.0/clap/struct.App.html#examples-48
How to test
As for me, I'm using fish shell and it works
mask init fish | source
Types of changes