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

Cargo should give helpful errors when unsupported flags are used. #11702

Closed
9 of 10 tasks
jonhoo opened this issue Feb 11, 2023 · 11 comments · Fixed by #12811
Closed
9 of 10 tasks

Cargo should give helpful errors when unsupported flags are used. #11702

jonhoo opened this issue Feb 11, 2023 · 11 comments · Fixed by #12811
Assignees
Labels
A-cli Area: Command-line interface, option parsing, etc. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` E-easy Experience: Easy S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@jonhoo
Copy link
Contributor

jonhoo commented Feb 11, 2023

Problem

There are several flags one might imagine users passing to Cargo that aren't supported yet. It'd be nice if we told users who try to use these what to use instead, and perhaps also linked to the issue (if any) proposing to add such a flag. Some examples:

Proposed Solution

No response

Notes

No response

@jonhoo jonhoo added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Feb 11, 2023
@epage epage added the A-cli Area: Command-line interface, option parsing, etc. label Feb 11, 2023
@weihanglo
Copy link
Member

Does it make sense having this as a built-in mechanism in clap for suggesting an alternative flag?

@epage
Copy link
Contributor

epage commented Feb 13, 2023

@weihanglo I think that can make sense to seed clap with specific suggestions and not just rely on the automatic suggestions and that would help simplify things for application, like cargo. Mind opening an issue?

@weihanglo
Copy link
Member

weihanglo commented Apr 21, 2023

More examples:

  • There's no --debug for cargo build. Only --release.
  • There's no --release for cargo install. Only --debug.

These does confuse people a lot. See #12009.

@weihanglo
Copy link
Member

weihanglo commented Apr 21, 2023

I am not sure if we should wait for upstream fix or make our own custom suggestion. Let's label it as waiting for upstream first. We still seek ad-hoc solutions if somebody is interested in.

@rustbot label +S-blocked-external

@rustbot rustbot added the S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix label Apr 21, 2023
@weihanglo
Copy link
Member

clap-rs/clap#5075 just got landed with clap@4.3.22. People, we now can have basic suggestions for unsupported arguments!

I'll write down a list of flags of interest and instructions shortly.

@rustbot label -S-blocked-external +S-accepted +E-easy

@rustbot rustbot added E-easy Experience: Easy S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review and removed S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix labels Aug 17, 2023
@weihanglo
Copy link
Member

Not sure if this is the relevant clap issue clap-rs/clap#4853. Supposed we are going to leverage UnknownArgumentValueParser for those well-known unknown arguments, it might cause unwanted typo suggestion for them.

Let me label it blocked on that issue at this moment.

@rustbot label -S-accepted +S-blocked-external

@rustbot rustbot added S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix and removed S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review labels Aug 22, 2023
@epage
Copy link
Contributor

epage commented Aug 22, 2023

@weihanglo could you give an example of where that causes a problem worth blocking this issue?

@weihanglo
Copy link
Member

Something like this? Though for short aliases clap doesn't suggest them I feel like. If that's the case we can continue working on short aliases part.

    Finished dev [unoptimized + debuginfo] target(s) in 0.16s
     Running `target/debug/cargo install --please`
error: unexpected argument '--please' found

  tip: a similar argument exists: '--release'

Usage: cargo install --release [crate]...

For more information, try '--help'.

@epage
Copy link
Contributor

epage commented Aug 23, 2023

Asking to better characterize the problem: is that always bad though?

Take the prior work in #12529, like cargo test --keep-going. If the user thought it should work and did cargo test --keep-goign, today they would get a correction and then be pointed to the correct flag (yes, ideally the two steps would be one step which might be a consideration where suggest_arg is appropriate). With the proposed change, the user would just get an unexpected argument error and would fall back to --help. Trying to understand which path is best.

@weihanglo
Copy link
Member

It's not inherently bad, and agree with that two steps is better than infinite steps searching in --help. Just it is lying that “a similar argument exists”, which doesn't.

I am convinced that it's not really a blocker 😆. Would be great if clap can improve the situation.

@rustbot label +S-accepted -S-blocked-external

@rustbot rustbot added S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review and removed S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix labels Aug 23, 2023
@hi-rustin
Copy link
Member

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Area: Command-line interface, option parsing, etc. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` E-easy Experience: Easy S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants