Add 'parse(from_occurrences)' parser. Don't special case 'u64'.#48
Add 'parse(from_occurrences)' parser. Don't special case 'u64'.#48TeXitoi merged 2 commits intoTeXitoi:masterfrom
Conversation
|
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. |
structopt-derive/src/lib.rs
Outdated
| //! | `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) | |
There was a problem hiding this comment.
| 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).
There was a problem hiding this comment.
Sounds good! Will make this change (and the others) soon.
There was a problem hiding this comment.
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.
structopt-derive/src/lib.rs
Outdated
| 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. |
tests/flags.rs
Outdated
| assert_eq!(Opt { alice: 0, bob: 0 }, | ||
| Opt::from_clap(Opt::clap().get_matches_from(&["test"]))); | ||
| assert_eq!(Opt { alice: 1 }, | ||
| assert_eq!(Opt { alice: 1, bob: 0}, |
|
Great work! |
|
Okay! Now using |
Fixes #30. Can change to
from_occurrencesif you'd like.