Skip to content

clap v2 #399

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

Merged
merged 43 commits into from
Jan 29, 2016
Merged

clap v2 #399

merged 43 commits into from
Jan 29, 2016

Conversation

kbknapp
Copy link
Member

@kbknapp kbknapp commented Jan 28, 2016

Finally ready...

This commit implements the base changes for clap 2.x
This commit adds support for values separated by commas such as
--option=val1,val2,val3. It also includes support for uses
without the equals and shorts (both with and without)

--option=val1,val2
--option val1,val2
-oval1,val2
-o=val1,val2
-o val1,val2

Closes #348
By using AppSettings::AllowLeadingHyphen values starting with a
leading hyphen (such as a negative number) are supported. This
setting should be used with caution as it silences certain
circumstances which would otherwise be an error (like forgetting
a value to an option argument).

Closes #385
External subcommands are now supported via the following:

```rust
extern crate clap;
use clap::{App, AppSettings};

fn main() {
    // Assume there is a third party subcommand named myprog-subcmd
    let m = App::new("myprog")
        .setting(AppSettings::AllowExternalSubcommands)
        .get_matches_from(vec![
            "myprog", "subcmd", "--option", "value", "-fff", "--flag"
        ]);
    // All trailing arguments will be stored under the subcommands sub-matches under a
    // value of their runtime name (in this case "subcmd")
    match m.subcommand() {
        (external, Some(ext_m)) => {
            let ext_args: Vec<&str> = ext_m.values_of(external).unwrap().collect();
            assert_eq!(ext_args ,["--option", "value", "-fff", "--flag"]);
        },
        _ => unreachable!()
   }
}
```

Closes #372
}

fn cause(&self) -> Option<&Error> {
match self.error_type {
fn cause(&self) -> Option<&StdError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

cause is provided. It's better not to override it if it's not used for something. I don't know if this is used for something...

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't know it provided a default impl, good catch!

Fixed.

@sru
Copy link
Contributor

sru commented Jan 29, 2016

I went through all the changes that I could see in GitHub webpage briefly. I am not sure about going through all other changes because I don't know how to comment those. I must say, good work!

@kbknapp
Copy link
Member Author

kbknapp commented Jan 29, 2016

@sru I really appreciate the detailed look! All great comments and catches!

@kbknapp
Copy link
Member Author

kbknapp commented Jan 29, 2016

@Vinatorul if you wouldn't mind taking a look too since this is a big merge 😉

@Vinatorul
Copy link
Contributor

@kbknapp ok, I will look into it now.

@@ -254,6 +259,7 @@ fn multiple_values_of_option_max_more() {
.short("o")
.help("multiple options")
.takes_value(true)
.multiple(true)
Copy link
Contributor

Choose a reason for hiding this comment

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

max_values implicitly sets multiple to true isn't it?

@Vinatorul
Copy link
Contributor

@kbknapp All looks great, I have little questions about tests, somewhere multiple appears, somewhere dissapears.

@kbknapp
Copy link
Member Author

kbknapp commented Jan 29, 2016

@Vinatorul nope it doesn't implicitly set it to multiple. I'm making a hard stance between multiple values and multiple occurrences.

# multiple values, one occurrence
$ -o va1 val2 val3

# multiple occurences
$ -o -o -o -o

# multiple occurrences and multiple values
$ -o val1 -o val2 -o val3

# still multiple occurrences, and multiple values (but here number_of_values(2) has presumably been set)
$ -o val1 val2 -o val3 val4

I think this, although somewhat confusing at first will be more explicit in the long run. max_values, min_values, and number_of_values deal with multiple values and not multiple occurrence.

}

#[test]
Copy link
Contributor

Choose a reason for hiding this comment

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

This tests looks like unit tests

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps, but we can shuffle around where the test lies at a later date when we re-organize some things. 😜

@Vinatorul
Copy link
Contributor

@kbknapp Ah, I see you have deleted this, github repo search tricks me. I thought I was searching in v2-master but it switched to current master

@Vinatorul
Copy link
Contributor

As I see conflict_overriden_2 now works fine, thats pretty cool, have you mentioned this in breaking changes?

@Vinatorul
Copy link
Contributor

@kbknapp Is it intentionally that you have added first param (binary name) in every test except group? Or it doesn't matter?

@kbknapp
Copy link
Member Author

kbknapp commented Jan 29, 2016

@sru @Vinatorul

If y'all are good with it, I'll let one of you do the honors and merge whenever ready! 👍

@Vinatorul
Copy link
Contributor

@kbknapp only homu have this right :)

@kbknapp
Copy link
Member Author

kbknapp commented Jan 29, 2016

@Vinatorul I added the binary name in examples so as not to confuse people, but for tests it doesn't really matter.

The conflicts overridden is one I'm not 100% sure what the original did...so if it might be one of those technically breaking changes which wasn't supposed to be broken in the first place. So we'll see if anyone files a bug report against it, but I doubt it as POSIX overrides aren't super common.

Here goes...

@homu r+

@homu
Copy link
Contributor

homu commented Jan 29, 2016

📌 Commit 9054274 has been approved by kbknapp

homu added a commit that referenced this pull request Jan 29, 2016
@homu
Copy link
Contributor

homu commented Jan 29, 2016

⚡ Test exempted - status

@homu homu merged commit 9054274 into master Jan 29, 2016
@kbknapp kbknapp deleted the rebase-v2 branch January 29, 2016 14:44
@Vinatorul
Copy link
Contributor

@kbknapp that was the bug of old parser. The problem was that old parsed checked conflicts on each interation. As I see now parser firtly will get all arguments, before checking conflicts

@Vinatorul
Copy link
Contributor

@kbknapp I think you should tweet and crete post on reddit about v2

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