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

Fix a regression with parsing multivalue options #5196

Merged
merged 1 commit into from
Mar 16, 2018

Conversation

matklad
Copy link
Member

@matklad matklad commented Mar 16, 2018

By default, clap interprets

cargo run --bin foo bar baz

as

cargo run --bin foo --bin bar --bin baz

This behavior is different from docopt and does not play nicely with
positional arguments at all. Luckily, clap has a flag to get the
behavior we want, it just not the default! It will become the default in
the next version of clap, but, until that time, we should be careful
when using the combination of .long, .value_name and
.multiple(true), and don't forget to specify .number_of_values(1) as
well.

@alexcrichton I'd love to merge this fix before updating cargo at rust-lang/rust :)

By default, clap interprets

```
cargo run --bin foo bar baz
```

as

```
cargo run --bin foo --bin bar --bin baz
```

This behavior is different from docopt and does not play nicely with
positional arguments at all. Luckily, clap has a flag to get the
behavior we want, it just not the default! It will become the default in
the next version of clap, but, until that time, we should be careful
when using the combination of `.long`, `.value_name` and
`.multiple(true)`, and don't forget to specify `.number_of_values(1)` as
well.
@rust-highfive
Copy link

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

.arg("hello")
.arg("world"),
execs().with_status(0),
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to the PR, but do you feel like making p.cargo a little bit more magical, so that

    assert_that(
        p.cargo("run --bin foo hello world"),
        execs().with_status(0),
    );

works?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be totally down for that!

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Collaborator

bors commented Mar 16, 2018

📌 Commit 70ff33a has been approved by alexcrichton

@bors
Copy link
Collaborator

bors commented Mar 16, 2018

⌛ Testing commit 70ff33a with merge d6c3983...

bors added a commit that referenced this pull request Mar 16, 2018
Fix a regression with parsing multivalue options

By default, clap interprets

```
cargo run --bin foo bar baz
```

as

```
cargo run --bin foo --bin bar --bin baz
```

This behavior is different from docopt and does not play nicely with
positional arguments at all. Luckily, clap has a flag to get the
behavior we want, it just not the default! It will become the default in
the next version of clap, but, until that time, we should be careful
when using the combination of `.long`, `.value_name` and
`.multiple(true)`, and don't forget to specify `.number_of_values(1)` as
well.

@alexcrichton I'd love to merge this fix before updating cargo at rust-lang/rust :)
@bors
Copy link
Collaborator

bors commented Mar 16, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing d6c3983 to master...

@bors bors merged commit 70ff33a into rust-lang:master Mar 16, 2018
@matklad matklad deleted the clapclapclap branch March 16, 2018 16:42
bors added a commit that referenced this pull request Mar 16, 2018
Slightly improve ergonomics of writing Cargo tests

As discussed in #5196 (comment)

I've also employed this to some of the longer command-lines in our test suite :)
@ehuss ehuss added this to the 1.26.0 milestone Feb 6, 2022
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