fix(Indices): fixes Indices to work on v3

This commit is contained in:
Kevin K 2018-03-03 21:04:28 -05:00
parent e2e15b79b7
commit f65e2e4bf5
No known key found for this signature in database
GPG key ID: 17218E4B3692F01A
3 changed files with 21 additions and 20 deletions

View file

@ -108,6 +108,7 @@ where
num_flags: 0,
positionals: VecMap::new(),
seen: Vec::new(),
cur_idx: Cell::new(0),
}
}
@ -489,7 +490,7 @@ where
let low_index_mults = self.is_set(AS::LowIndexMultiplePositional)
&& pos_counter == (self.positionals.len() - 1);
let missing_pos = self.is_set(AS::AllowMissingPositional)
&& (pos_counter == (self.positionals.len() - 1)
&& (pos_counter == (self.positionals.len() - 1)
&& !self.is_set(AS::TrailingValues));
debugln!(
"Parser::get_matches_with: Positional counter...{}",
@ -1193,20 +1194,20 @@ where
) -> ClapResult<ParseResult<'a>> {
debugln!("Parser::add_single_val_to_arg;");
debugln!("Parser::add_single_val_to_arg: adding val...{:?}", v);
// update the current index because each value is a distinct index to clap
self.cur_idx.set(self.cur_idx.get() + 1);
// @TODO @docs @p4 docs should probably note that terminator doesn't get an index
if let Some(t) = arg.terminator {
if t == v {
return Ok(ParseResult::ValuesDone);
}
}
matcher.add_val_to(arg.name, v);
matcher.add_index_to(arg.name, self.cur_idx.get());
// Increment or create the group "args"
if let Some(grps) = self.groups_for_arg(arg.name) {
for grp in grps {
@ -1229,7 +1230,7 @@ where
matcher.inc_occurrence_of(flag.name);
matcher.add_index_to(flag.name, self.cur_idx.get());
// Increment or create the group "args"
self.groups_for_arg(flag.name)
.and_then(|vec| Some(matcher.inc_occurrences_of(&*vec)));

View file

@ -549,7 +549,7 @@ impl<'a> ArgMatches<'a> {
/// .multiple(true))
/// .arg(Arg::with_name("flag")
/// .short("f")
/// .multiple(true))
/// .multiple_occurrences(true))
/// .get_matches_from(vec!["myapp", "-o", "val1", "-f", "-o", "val2", "-f"]);
/// // ARGV idices: ^0 ^1 ^2 ^3 ^4 ^5 ^6
/// // clap idices: ^2 ^3 ^5 ^6

View file

@ -57,10 +57,10 @@ fn index_flags() {
let m = App::new("ind")
.arg(Arg::with_name("exclude")
.short("e")
.multiple(true))
.multiple_occurrences(true))
.arg(Arg::with_name("include")
.short("i")
.multiple(true))
.multiple_occurrences(true))
.get_matches_from(vec!["ind", "-e", "-i", "-e", "-e", "-i"]);
assert_eq!(m.index_of("exclude"), Some(1));
@ -72,10 +72,10 @@ fn indices_mult_flags() {
let m = App::new("ind")
.arg(Arg::with_name("exclude")
.short("e")
.multiple(true))
.multiple_occurrences(true))
.arg(Arg::with_name("include")
.short("i")
.multiple(true))
.multiple_occurrences(true))
.get_matches_from(vec!["ind", "-e", "-i", "-e", "-e", "-i"]);
assert_eq!(m.indices_of("exclude").unwrap().collect::<Vec<_>>(), &[1, 3, 4]);
@ -87,10 +87,10 @@ fn indices_mult_flags_combined() {
let m = App::new("ind")
.arg(Arg::with_name("exclude")
.short("e")
.multiple(true))
.multiple_occurrences(true))
.arg(Arg::with_name("include")
.short("i")
.multiple(true))
.multiple_occurrences(true))
.get_matches_from(vec!["ind", "-eieei"]);
assert_eq!(m.indices_of("exclude").unwrap().collect::<Vec<_>>(), &[1, 3, 4]);
@ -102,10 +102,10 @@ fn indices_mult_flags_opt_combined() {
let m = App::new("ind")
.arg(Arg::with_name("exclude")
.short("e")
.multiple(true))
.multiple_occurrences(true))
.arg(Arg::with_name("include")
.short("i")
.multiple(true))
.multiple_occurrences(true))
.arg(Arg::with_name("option")
.short("o")
.takes_value(true))
@ -121,10 +121,10 @@ fn indices_mult_flags_opt_combined_eq() {
let m = App::new("ind")
.arg(Arg::with_name("exclude")
.short("e")
.multiple(true))
.multiple_occurrences(true))
.arg(Arg::with_name("include")
.short("i")
.multiple(true))
.multiple_occurrences(true))
.arg(Arg::with_name("option")
.short("o")
.takes_value(true))
@ -164,12 +164,12 @@ fn indices_mult_opt_mult_flag() {
.arg(Arg::with_name("option")
.short("o")
.takes_value(true)
.multiple(true))
.multiple_occurrences(true))
.arg(Arg::with_name("flag")
.short("f")
.multiple(true))
.multiple_occurrences(true))
.get_matches_from(vec!["myapp", "-o", "val1", "-f", "-o", "val2", "-f"]);
assert_eq!(m.indices_of("option").unwrap().collect::<Vec<_>>(), &[2, 5]);
assert_eq!(m.indices_of("flag").unwrap().collect::<Vec<_>>(), &[3, 6]);
}
}