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

With CARGO_COMPLETE, --target, --bin, etc show both values and flags #14606

Open
epage opened this issue Sep 27, 2024 · 4 comments
Open

With CARGO_COMPLETE, --target, --bin, etc show both values and flags #14606

epage opened this issue Sep 27, 2024 · 4 comments
Labels
A-completions Area: shell completions C-enhancement Category: enhancement S-needs-team-input Status: Needs input from team on whether/how to proceed.

Comments

@epage
Copy link
Contributor

epage commented Sep 27, 2024

For example
Image

@epage epage added A-completions Area: shell completions C-enhancement Category: enhancement S-needs-team-input Status: Needs input from team on whether/how to proceed. labels Sep 27, 2024
@epage
Copy link
Contributor Author

epage commented Sep 27, 2024

This is because Cargo tells clap that these arguments take num_args(0..=1)
Image

Cargo offers the 0-value variant for people to look up supported values
Image

@epage
Copy link
Contributor Author

epage commented Sep 27, 2024

Options

  • Remove the num_args(0..=1) behavior
  • Somehow tell clap_complete about this special case

@epage
Copy link
Contributor Author

epage commented Sep 27, 2024

Combined with clap-rs/clap#5752, this makes it harder to see relevant completions on zsh

@epage epage changed the title With CARGO_COMPLETE, --target, --bin, etc show both values and falgs With CARGO_COMPLETE, --target, --bin, etc show both values and flags Oct 8, 2024
@epage
Copy link
Contributor Author

epage commented Oct 8, 2024

The Cargo team talked about this. Its not great we lie to clap to get the error reporting we want. If we want to keep our quality of errors is to then have a way to annotate clap with possible values that are dynamically generated from arg matches.

On clap's side, it wouldn't work to be context-aware because we validate num_args in the middle of parsing
https:/clap-rs/clap/blob/61f5ee514f8f60ed8f04c6494bdf36c19e7a8126/clap_builder/src/parser/parser.rs#L1316-L1327

Another idea is to support cargo check --target ?. That requires name validation for any arguments to happen later (which I think is currently the case). This would also be treated as a glob if there is a single-letter file name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completions Area: shell completions C-enhancement Category: enhancement S-needs-team-input Status: Needs input from team on whether/how to proceed.
Projects
None yet
Development

No branches or pull requests

1 participant