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

feature: cli completions #200

Merged
merged 1 commit into from
May 3, 2021
Merged

feature: cli completions #200

merged 1 commit into from
May 3, 2021

Conversation

XyLyXyRR
Copy link
Contributor

@XyLyXyRR XyLyXyRR commented May 1, 2021

Hi, there. I just impl completions for this project.

But there is a little awkward. clap 3-beta doesn't have 'completions' right now, so I downgrade to clap 2. (x
And a little ugly code to handle these differences.

Thank you.

@ajeetdsouza ajeetdsouza force-pushed the main branch 8 times, most recently from 37c2622 to a285b4e Compare May 2, 2021 00:34
@ajeetdsouza
Copy link
Owner

Hey @XyLyXyRR, thanks for your work on this!

clap v3 does actually support shell completions. I'm not sure how good they are, but I suppose it wouldn't hurt to include a version-controlled directory with autogenerated completions from clap while we test them out. Unfortunately, that would require reworking your current implementation.

The way I would go about this is:

  • Use the generate_to function in build.rs to generate completions at compile time. The way it's done is admittedly a little hacky, but the exact procedure is given in the documentation.
  • The include!("src/cli.rs"); line requires the whole app to be specified in a single file with no crate dependencies.
    • Move all the current App-related structs out into src/app.rs.
    • Rename crate::cmd::Cmd to crate::run::Run.
    • Let crate::run::<subcommand> import from crate::app::<subcommand>.
  • Use clap_generate::generate_to to write completions to contrib/completions. We can move it out of contrib once it's sufficiently stable. Use include!(src/app.rs); for getting the struct, and convert the struct to an app using into_app.

PS: the issue you linked actually refers to completions for z using zoxide query -l, which would not be fixed by this PR, so I've removed it from the PR description.

@XyLyXyRR
Copy link
Contributor Author

XyLyXyRR commented May 3, 2021

Hey @ajeetdsouza, I finished it.

Have a good day!

@ajeetdsouza
Copy link
Owner

This is great, thank you!

@ajeetdsouza ajeetdsouza merged commit ef63b55 into ajeetdsouza:main May 3, 2021
@XyLyXyRR XyLyXyRR deleted the feat/completions branch May 3, 2021 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants