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

The require_unless_one only works for the first argument name in array #575

Closed
volks73 opened this issue Jul 8, 2016 · 2 comments
Closed
Assignees
Labels
A-parsing Area: Parser's logic and needs it changed somehow. C-bug Category: Updating dependencies

Comments

@volks73
Copy link
Contributor

volks73 commented Jul 8, 2016

Let me start by saying that this library (crate) is amazing. It has been a lot of fun creating small CLI applications with Rust and this library. This is also my first time submitting an issue on Github.

I have been trying to use the require_unless_one function for an argument. It appears to only work for the first argument name in the array. From the documentation, this works:

let res = App::new("unlessone")
    .arg(Arg::with_name("cfg")
        .required_unless_one(&["dbg", "infile"])
        .takes_value(true)
        .long("config"))
    .arg(Arg::with_name("dbg")
        .long("debug"))
    .arg(Arg::with_name("infile")
        .short("i")
        .takes_value(true))
    .get_matches_from_safe(vec![
        "unlessone", "--debug"
    ]);

    assert!(res.is_ok());
    let m = res.unwrap();
    assert!(m.is_present("dbg"));
    assert!(!m.is_present("cfg"));

But the following does not appear to work:

let res = App::new("unlessone")
    .arg(Arg::with_name("cfg")
        .required_unless_one(&["dbg", "infile"])
        .takes_value(true)
        .long("config"))
    .arg(Arg::with_name("dbg")
        .long("debug"))
    .arg(Arg::with_name("infile")
        .short("i")
        .takes_value(true))
    .get_matches_from_safe(vec![
        "unlessone", "-i", "file"
    ]);

    assert!(res.is_ok());
    let m = res.unwrap();
    assert!(m.is_present("infile"));
    assert!(!m.is_present("cfg"));

Note, I have specified the infile argument, which is the second value in the array for the required_unless_one function. I have forked the repository and added a test for the second example. It currently fails. I have not had a chance to find the issue in the source code yet, but I thought I could at least submit an issue and a pull request that adds the test.

I am using the latest release version of clap (v2.9.2) on Mac OSX with Rust 1.9.0 stable.

@kbknapp
Copy link
Member

kbknapp commented Jul 23, 2016

Thanks for filing this, and also the PR 😉 I apologize for the time it's taken me to get to this; I've been traveling for my job. I'm going to look through your PR and we should be able to get this fixed quickly. 👍

@kbknapp kbknapp added C-bug Category: Updating dependencies P2: need to have A-parsing Area: Parser's logic and needs it changed somehow. labels Jul 23, 2016
@kbknapp kbknapp self-assigned this Jul 23, 2016
@kbknapp
Copy link
Member

kbknapp commented Jul 23, 2016

#595 fixes this

@homu homu closed this as completed in 1fc3b55 Jul 23, 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