Skip to content

Commit

Permalink
fix(matched_arg): Allow for more than 256 occurrences of an argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceri Storey committed Feb 2, 2016
1 parent bc091c4 commit 3731ddb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/args/arg_matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion src/args/matched_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}
Expand Down
13 changes: 12 additions & 1 deletion tests/multiple_occurrences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,15 @@ fn multiple_occurrences_of_flags_mixed() {
assert_eq!(m.occurrences_of("multflag2"), 2);
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);
}

0 comments on commit 3731ddb

Please sign in to comment.