Closed dbrgn closed 2 years ago
How would we feel about a tldr completions <bash|zsh|fish>
subcommand or tldr --completions <bash|zsh|fish>
flag that generates the completions to stdout?
I've noticed some other CLI apps I use do this, so just wanted to point it out as an additional option.
While I see your point, I don't think it's worth the additional CLI option (which increases complexity) for a feature that is mostly relevant for packagers (not really for end users) and will only be used max once per installation.
clap_generate
was depractated and moved to a new crate called clap_complete
in clap v3 https://crates.io/crates/clap_complete
The way I see to do this involves creating a build.rs script described here. But I'm unsure of how to use this with our Args
struct that derives Parser
, because it appears that clap_complete::generate_to
requires a clap::App
struct as an argument. https://docs.rs/clap_complete/latest/clap_complete/generator/fn.generate_to.html
If I understand correctly, what you are proposing has already been tried in #256, which was closed because dynamic completion of pages did not work with the generated completions - or are you proposing something else?
Oh I see, so we want it to complete the page lookups, and not just the flags, correct?
How is this done currently?
All three shells we support do support such dynamic completion. Currently, we write the completion files by hand and make use of the features (see usages of tldr --list
in the completion files in completion/
).
This is of course not optimal, because each completion needs to be kept up to date and in sync with each other - I just found a bug with the fish one (#268)
Yeah, until clap supports such dynamic lookups, it's probably best to close this issue.
Replace our manually-written completion files for bash, zsh and fish with auto-generated completion files.
Clap supports this through https://github.com/clap-rs/clap/tree/master/clap_generate.
These completion files don't need to be checked in, instead the release build script should generate them. Additionally, the README could contain a section on how to generate these completions (might be interesting for packagers).