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

Add 'parse(from_occurrences)' parser. Don't special case 'u64'. #48

Merged
merged 2 commits into from Feb 3, 2018

Conversation

Projects
None yet
2 participants
@SergioBenitez
Copy link
Contributor

commented Jan 28, 2018

Fixes #30. Can change to from_occurrences if you'd like.

@SergioBenitez SergioBenitez force-pushed the SergioBenitez:master branch from c70b940 to ec1bebd Jan 28, 2018

@TeXitoi TeXitoi added the v0.2 label Jan 29, 2018

@TeXitoi

This comment has been minimized.

Copy link
Owner

commented Jan 29, 2018

Thanks for the contribution!

Note that's a breaking change. I would like to pass another breaking change for v0.2 (#49), so publishing v0.2 will not happen before these 2 breaking change are done.

//!
//! | Kind | Signature | Default |
//! |-------------------|---------------------------------------|---------------------------------|
//! | `from_str` | `fn(&str) -> T` | `::std::convert::From::from` |
//! | `try_from_str` | `fn(&str) -> Result<T, E>` | `::std::str::FromStr::from_str` |
//! | `from_os_str` | `fn(&OsStr) -> T` | `::std::convert::From::from` |
//! | `try_from_os_str` | `fn(&OsStr) -> Result<T, OsString>` | (no default function) |
//! | `multiple` | (no signature) | (no default function) |

This comment has been minimized.

Copy link
@TeXitoi

TeXitoi Jan 29, 2018

Owner

| from_occurrences | fn(u64) -> T | value as T |

It would be great to have a consistent name as from_occurrences and have the possibility to give a conversion function (for transforming the number to an Enum for example).

This comment has been minimized.

Copy link
@SergioBenitez

SergioBenitez Jan 29, 2018

Author Contributor

Sounds good! Will make this change (and the others) soon.

This comment has been minimized.

Copy link
@SergioBenitez

SergioBenitez Jan 30, 2018

Author Contributor

We should probably take an fn(u64) -> Result<T, E> so that you can accept some number of flags and not other, i.e, if you only have three verbosity levels and want to enforce that. Nevermind. Unfortunately this isn't the way validator works for occurrences in clap.

@TeXitoi
Copy link
Owner

left a comment

Only minor cosmetic changes

@@ -370,6 +373,8 @@ enum Parser {
FromOsStr,
/// Parse an option to using a `fn(&OsStr) -> Result<T, OsString>` function.
TryFromOsStr,
/// Doesn't take a value. Instead, count the number of repitions.

This comment has been minimized.

Copy link
@TeXitoi
Opt::from_clap(Opt::clap().get_matches_from(&["test"])));
assert_eq!(Opt { alice: 1 },
assert_eq!(Opt { alice: 1, bob: 0},

This comment has been minimized.

Copy link
@TeXitoi

TeXitoi Jan 29, 2018

Owner

Lack space before }

@TeXitoi

This comment has been minimized.

Copy link
Owner

commented Jan 29, 2018

Great work!

@SergioBenitez SergioBenitez force-pushed the SergioBenitez:master branch from 35387d0 to 863bc55 Jan 30, 2018

@SergioBenitez

This comment has been minimized.

Copy link
Contributor Author

commented Jan 30, 2018

Okay! Now using parse(from_occurrences) which allows a custom parser from u64 -> T.

@TeXitoi
Copy link
Owner

left a comment

Thanks a lot! Seems perfect.

@SergioBenitez SergioBenitez changed the title Add 'parse(multiple)' parser. Don't special case 'u64'. Add 'parse(from_occurrences)' parser. Don't special case 'u64'. Jan 31, 2018

@TeXitoi TeXitoi merged commit 35423c9 into TeXitoi:master Feb 3, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

TeXitoi added a commit that referenced this pull request Feb 3, 2018

@CAD97 CAD97 referenced this pull request Feb 17, 2018

Merged

Re-license to Apache-2.0/MIT #71

11 of 11 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.