fix(matched_arg): Allow for more than 256 occurrences of an argument.

This commit is contained in:
Ceri Storey 2016-02-02 17:57:02 +00:00
parent bc091c4a78
commit 3731ddb361
3 changed files with 14 additions and 3 deletions

View file

@ -326,7 +326,7 @@ impl<'a> ArgMatches<'a> {
/// assert_eq!(m.occurrences_of("debug"), 3);
/// assert_eq!(m.occurrences_of("flag"), 1);
/// ```
pub fn occurrences_of<S: AsRef<str>>(&self, name: S) -> u8 {
pub fn occurrences_of<S: AsRef<str>>(&self, name: S) -> u64 {
self.args.get(name.as_ref()).map_or(0, |a| a.occurs)
}

View file

@ -6,7 +6,7 @@ use vec_map::VecMap;
#[derive(Debug, Clone)]
pub struct MatchedArg {
#[doc(hidden)]
pub occurs: u8,
pub occurs: u64,
#[doc(hidden)]
pub vals: VecMap<OsString>,
}

View file

@ -63,3 +63,14 @@ fn multiple_occurrences_of_flags_mixed() {
assert!(m.is_present("flag"));
assert_eq!(m.occurrences_of("flag"), 1);
}
#[test]
fn multiple_occurrences_of_flags_large_quantity() {
let args : Vec<&str> = vec![""].into_iter().chain(vec!["-m"; 1024].into_iter()).collect();
let m = App::new("multiple_occurrences")
.arg(Arg::from_usage("-m --multflag 'allowed multiple flag'")
.multiple(true))
.get_matches_from(args);
assert!(m.is_present("multflag"));
assert_eq!(m.occurrences_of("multflag"), 1024);
}