cargo icon indicating copy to clipboard operation
cargo copied to clipboard

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

Open epage opened this issue 1 year ago • 4 comments

For example Image

epage avatar Sep 27 '24 15:09 epage

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 avatar Sep 27 '24 15:09 epage

Options

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

epage avatar Sep 27 '24 15:09 epage

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

epage avatar Sep 27 '24 15:09 epage

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://github.com/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.

epage avatar Oct 08 '24 14:10 epage