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

Enhance error messages, check argument names for correctness #2995

Closed
2 tasks done
Tastaturtaste opened this issue Nov 5, 2021 · 3 comments
Closed
2 tasks done

Enhance error messages, check argument names for correctness #2995

Tastaturtaste opened this issue Nov 5, 2021 · 3 comments

Comments

@Tastaturtaste
Copy link

Tastaturtaste commented Nov 5, 2021

Please complete the following tasks

  • I have searched the discussions
  • I have searched the existing issues

Clap Version

2.33.3

Describe your use case

Enhance error reporting to better guide the user to the underlying issue and to the corresponding documentation.
The (minimalized) issue triggering this request was me trying to set a argument as follows:

use clap::{App, Arg};

fn main() {
    let args = App::new("prog")
        .arg(Arg::with_name("flag").long("flag").short("ff"))
        .get_matches_from(vec!["prog", "-ff"]);
    println!("{:?}", args);
}

As you can see I foolishly tried to set .short("ff") which does not work since only the first non - character is used as the short argument.
While the docs are quite clear about it, the error message I got is much less useful in my opinion:

error: The argument '--flag' was provided more than once, but cannot be used multiple times

My original use case involved more arguments, custom parsing, structopt, etc. and the cause of this issue was very much not obvious to me.

Describe the solution you'd like

What I would have liked to happen would be a Error or panic! out of the .short method, even before matching of the actual arguments happens, indicating that the provided short-name is not allowed.
While the docs are clear regarding this issue I did not even know to look there, instead thinking my custom parsing or the order of arguments messed some things up.

Alternatives, if applicable

No response

Additional Context

No response

@epage
Copy link
Member

epage commented Nov 5, 2021

.short("ff")

clap v3 changed the type for short from &str to char, so this will now be a compile-time error.

@Tastaturtaste
Copy link
Author

Wow, nice. I should maybe switch to the beta.
Also, that has to be one of the fastest responses I ever got on github, thanks 👍

@epage
Copy link
Member

epage commented Nov 5, 2021

Docs are a weak point; we are waiting to see how things shake up first. You can track how close we are at https://github.com/clap-rs/clap/milestone/76.

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

No branches or pull requests

2 participants