clap
clap copied to clipboard
Allow for generating a "catch-all" branch when generating completions
Please complete the following tasks
- [X] I have searched the discussions
- [X] I have searched the open and rejected issues
Clap Version
3.1.9
Describe your use case
cargo
(and other things like git) allows for surfacing third-party completions https://github.com/rust-lang/cargo/blob/9fa2bba6791f9df06a13dbfe18bf7add9b9b2d1b/src/etc/_cargo#L341 (for zsh anyway) by assuming they are defined as _cargo-<name>
. It would be a nice feature if clap_complete
could generate a similar "catch-all" branch for the purposes of delegating to completions provided by external commands. Currently, I'm generating completions then invoking some sed
magic to insert my own catch-all branch, but this is a little fragile (and I only have it working for zsh).
Describe the solution you'd like
My preferred solution would be something that would enable me to customize the way completions are generated in such a way that a "good enough" catch-all block was generated for me, though I realize generate
doesn't have a builder, so adding a flag like allow_fallback
or whatever would be a breaking change.
Alternatives, if applicable
Possible alternatives include
- a hook/template into the completion generation so arbitrary text could be added
- a separate function that allows for the generation of the catch-all branch (to not break current users)
Additional Context
No response
My preferred solution would be something that would enable me to customize the way completions are generated in such a way that a "good enough" catch-all block was generated for me,
I feel like there is too much policy in a "good enough" fallback to have one at the clap_complete
level.
The big issue is ideally we'd tag the Arg or Command with special behavior. We are looking at supporting that soon-ish. Say we go with the hook option you mentioned, we are looking at supporting arg.set(clap_complete::shell::BashCompleter::new("..."))
and the clap_complete
could check if that exists and get its value.