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

Requiring another argument by name from an argument that is itself required creates a duplicate error message #492

Closed
stensonowen opened this issue May 1, 2016 · 1 comment
Labels
A-parsing Area: Parser's logic and needs it changed somehow. C-bug Category: Updating dependencies

Comments

@stensonowen
Copy link

Hopefully the title is clear. In the example, argument foo is required, and it also requires bar.

let matches = App::new("MyApp")
                        .arg(Arg::with_name("foo")
                                    .help("FOO")
                                    .short("f")
                                    .required(true)
                                    .takes_value(true)
                                    .conflicts_with("c")
                                    .requires("bar")
                            )
                         .arg(Arg::with_name("bar")
                                    .short("b")
                                    .takes_value(true)
                                    .help("BAR")
                                    //.required(true)
                            )
                        .get_matches();

Calling ./prog --help returns what you'd expect (foo and bar are required, with the correct usage string), but supplying the -f flag produces the following error:

error: The following required arguments were not provided:
    -b <bar>
    -b <bar>

USAGE:
    repeat_errors [FLAGS] [OPTIONS] -f <foo> -b <bar> -b <bar>

(Uncommenting the bar.required(true) adds another -b <bar> to the error and usage.)
It's conceivable that someone would want a required argument that requires another, so there is understandably a use case in which this error occurs. Additionally, it is certainly possible for a user to have accidentally made bar required, and the usage mistake might easily go unnoticed.
Apologies if there's already a way to avoid these kinds of redundancies, but I didn't see any.
It seems like an interesting (albiet niche) problem, so I'll probably take a crack at solving it and make a pull request.

@kbknapp
Copy link
Member

kbknapp commented May 3, 2016

Thanks for filing! Yep, the title is clear 😄

I agree it's possible someone could end up doing this either by accident, or just not knowing there are other ways to accomplish this (i.e. if an arg is required by another required arg, it's not necessary to set).

I should have this fixed shortly!

@kbknapp kbknapp added C-bug Category: Updating dependencies P2: need to have A-parsing Area: Parser's logic and needs it changed somehow. labels May 3, 2016
kbknapp added a commit that referenced this issue May 3, 2016
kbknapp added a commit that referenced this issue May 3, 2016
@kbknapp kbknapp closed this as completed in 5b01200 May 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parsing Area: Parser's logic and needs it changed somehow. C-bug Category: Updating dependencies
Projects
None yet
Development

No branches or pull requests

2 participants