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

Error message should reference the short not long when short is used as arg #1249

Closed
polarathene opened this issue Apr 18, 2018 · 2 comments
Closed
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... A-parsing Area: Parser's logic and needs it changed somehow. A-validators Area: ArgMatches validation logi C-enhancement Category: Raise on the bar on expectations S-wont-fix Status: Closed as there is no plan to fix this

Comments

@polarathene
Copy link

Rust Version

1.25

Affected Version of clap

2.31.2

Expected Behavior Summary

Error should reference the short when used, not the long. Or at least also reference the short.

./target/debug/test -g not_a_valid_value
error: 'not_a_valid_value' isn't a valid value for '-g <NAME>'
        [possible values: opengl, vulkan]

or

./target/debug/test -g not_a_valid_value
error: 'not_a_valid_value' isn't a valid value for '-g / --force-renderer <NAME>'
        [possible values: opengl, vulkan]

Actual Behavior Summary

If a long is included, the error always references the long even when short is used for args.

./target/debug/test -g not_a_valid_value
error: 'not_a_valid_value' isn't a valid value for '--force-renderer <NAME>'
        [possible values: opengl, vulkan]

Sample Code or Link to Sample Code

extern crate clap;
use clap::{App,Arg};

fn main() {
    let matches = App::new("myapp")
        .arg(Arg::with_name("NAME")
            .takes_value(true)
            .short("g")
            .long("force-renderer")
            .possible_values(&["opengl", "vulkan"])
        )
        .get_matches();
}
@kbknapp
Copy link
Member

kbknapp commented Jun 5, 2018

Agreed, however this one is slightly harder to fix than one would think as the arguments aren't stored as they're used, and clap does all error parsing at the end, so actually doens't know which version of the argument was used.

This isn't un-fixable, just harder as clap would need to keep track of which version was used (long/short). Also there are strange edge cases when someone use both version for flags/options that allow multiple values. Consider -o, --option <value>... style argument. If used like $ prog -o value1 --option value2 and there's an error should clap report the short or long? If one says, "whichever version was used for that particular error", then clap needs to also track which version was used with each value.

So again, it's not undoable, it's just hard 😜 Having said all this, I'll leave this open, but only as a very low priority. I need to get 3.x out sometime in the next few months.

@kbknapp kbknapp added C-enhancement Category: Raise on the bar on expectations P4: nice to have E-hard Call for participation: Experience needed to fix: Hard / a lot labels Jun 5, 2018
@pksunkara pksunkara added this to the 3.1 milestone Apr 9, 2020
@epage epage added A-help Area: documentation, including docs.rs, readme, examples, etc... A-parsing Area: Parser's logic and needs it changed somehow. A-validators Area: ArgMatches validation logi and removed C: errors labels Dec 8, 2021
@epage epage removed this from the 3.1 milestone Dec 8, 2021
@epage epage added S-waiting-on-mentor Status: Needs elaboration on the details before doing a 'Call for participation' and removed P4: nice to have E-hard Call for participation: Experience needed to fix: Hard / a lot labels Dec 9, 2021
@epage
Copy link
Member

epage commented Nov 8, 2022

We'd have to track this information per occurrence and track which occurrence we are validating at all times. The extra cost of us tracking this just for the error message does not seem worth it in terms of binary size, compile times, and memory usage.

In a way, the current behavior is better in that we clarify what the meaning of the short. By using a short, the user should be able to pick up on which of their arguments is being complained about though I could see it being nice to have rustc like error showing it in the line (if replace, defaults, and envs didn't cause problems)

As such, I lean towards closing this but we can re-open if people make the case for it.

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2022
@epage epage added S-wont-fix Status: Closed as there is no plan to fix this and removed S-waiting-on-mentor Status: Needs elaboration on the details before doing a 'Call for participation' labels Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... A-parsing Area: Parser's logic and needs it changed somehow. A-validators Area: ArgMatches validation logi C-enhancement Category: Raise on the bar on expectations S-wont-fix Status: Closed as there is no plan to fix this
Projects
None yet
Development

No branches or pull requests

4 participants