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

Issues 546,549 #551

Merged
merged 5 commits into from
Jun 30, 2016
Merged

Issues 546,549 #551

merged 5 commits into from
Jun 30, 2016

Conversation

kbknapp
Copy link
Member

@kbknapp kbknapp commented Jun 30, 2016

No description provided.

kbknapp added 4 commits June 29, 2016 22:57
…al delimiter to parse multiple values

Using this setting requires a value delimiter be present in order to parse multiple values.
Otherwise it is assumed no values follow, and moves on to the next arg with a clean slate.

These examples demonstrate what happens when `require_delimiter(true)` is used. Notice
everything works in this first example, as we use a delimiter, as expected.

```rust
let delims = App::new("reqdelims")
    .arg(Arg::with_name("opt")
        .short("o")
        .takes_value(true)
        .multiple(true)
        .require_delimiter(true))
    // Simulate "$ reqdelims -o val1,val2,val3"
    .get_matches_from(vec![
        "reqdelims", "-o", "val1,val2,val3",
    ]);

assert!(delims.is_present("opt"));
assert_eq!(delims.values_of("opt").unwrap().collect::<Vec<_>>(), ["val1", "val2", "val3"]);
```
In this next example, we will *not* use a delimiter. Notice it's now an error.

```rust
let res = App::new("reqdelims")
    .arg(Arg::with_name("opt")
        .short("o")
        .takes_value(true)
        .multiple(true)
        .require_delimiter(true))
    // Simulate "$ reqdelims -o val1 val2 val3"
    .get_matches_from_safe(vec![
        "reqdelims", "-o", "val1", "val2", "val3",
    ]);

assert!(res.is_err());
let err = res.unwrap_err();
assert_eq!(err.kind, ErrorKind::UnknownArgument);
```
What's happening is `-o` is getting `val1`, and because delimiters are required yet none
were present, it stops parsing `-o`. At this point it reaches `val2` and because no
positional arguments have been defined, it's an error of an unexpected argument.

In this final example, we contrast the above with `clap`'s default behavior where the above
is *not* an error.

```rust
let delims = App::new("reqdelims")
    .arg(Arg::with_name("opt")
        .short("o")
        .takes_value(true)
        .multiple(true))
    // Simulate "$ reqdelims -o val1 val2 val3"
    .get_matches_from(vec![
        "reqdelims", "-o", "val1", "val2", "val3",
    ]);

assert!(delims.is_present("opt"));
assert_eq!(delims.values_of("opt").unwrap().collect::<Vec<_>>(), ["val1", "val2", "val3"]);
```
…ll in just that portion

The functionality can now be found in https://crates.io/crates/term_size

Closes #549
@yo-bot
Copy link

yo-bot commented Jun 30, 2016

r? @sru

(yo-bot has picked a reviewer for you, use r? to override)

@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 84.771% when pulling e5ba93a on issues-546,549 into 40017ed on master.

@kbknapp
Copy link
Member Author

kbknapp commented Jun 30, 2016

@homu r+

@homu
Copy link
Contributor

homu commented Jun 30, 2016

📌 Commit e5ba93a has been approved by kbknapp

homu added a commit that referenced this pull request Jun 30, 2016
homu added a commit that referenced this pull request Jun 30, 2016
@homu
Copy link
Contributor

homu commented Jun 30, 2016

⌛ Testing commit e5ba93a with merge 3a000d6...

@homu
Copy link
Contributor

homu commented Jun 30, 2016

☀️ Test successful - status

@homu homu merged commit e5ba93a into master Jun 30, 2016
@kbknapp kbknapp deleted the issues-546,549 branch June 30, 2016 17:46
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

Successfully merging this pull request may close these issues.

5 participants