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

Auto-generate completion files through clap #220

Closed
dbrgn opened this issue Oct 17, 2021 · 8 comments
Closed

Auto-generate completion files through clap #220

dbrgn opened this issue Oct 17, 2021 · 8 comments
Labels
Milestone

Comments

@dbrgn
Copy link
Collaborator

dbrgn commented Oct 17, 2021

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).

@dbrgn dbrgn added the chore label Oct 17, 2021
@dbrgn dbrgn added this to the v1.5.1 milestone Jan 1, 2022
@dmaahs2017
Copy link
Contributor

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.

@dbrgn
Copy link
Collaborator Author

dbrgn commented Jan 28, 2022

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.

@dmaahs2017
Copy link
Contributor

clap_generate was depractated and moved to a new crate called clap_complete in clap v3 https://crates.io/crates/clap_complete

@dmaahs2017
Copy link
Contributor

dmaahs2017 commented Feb 12, 2022

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

@niklasmohrin
Copy link
Collaborator

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?

@dmaahs2017
Copy link
Contributor

dmaahs2017 commented Feb 13, 2022

Oh I see, so we want it to complete the page lookups, and not just the flags, correct?

How is this done currently?

@niklasmohrin
Copy link
Collaborator

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)

@dbrgn
Copy link
Collaborator Author

dbrgn commented Feb 13, 2022

Yeah, until clap supports such dynamic lookups, it's probably best to close this issue.

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

Successfully merging a pull request may close this issue.

3 participants