mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 14:22:34 +00:00
fix(Indices): fixes Indices to work on v3
This commit is contained in:
parent
e2e15b79b7
commit
f65e2e4bf5
3 changed files with 21 additions and 20 deletions
|
@ -108,6 +108,7 @@ where
|
||||||
num_flags: 0,
|
num_flags: 0,
|
||||||
positionals: VecMap::new(),
|
positionals: VecMap::new(),
|
||||||
seen: Vec::new(),
|
seen: Vec::new(),
|
||||||
|
cur_idx: Cell::new(0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -549,7 +549,7 @@ impl<'a> ArgMatches<'a> {
|
||||||
/// .multiple(true))
|
/// .multiple(true))
|
||||||
/// .arg(Arg::with_name("flag")
|
/// .arg(Arg::with_name("flag")
|
||||||
/// .short("f")
|
/// .short("f")
|
||||||
/// .multiple(true))
|
/// .multiple_occurrences(true))
|
||||||
/// .get_matches_from(vec!["myapp", "-o", "val1", "-f", "-o", "val2", "-f"]);
|
/// .get_matches_from(vec!["myapp", "-o", "val1", "-f", "-o", "val2", "-f"]);
|
||||||
/// // ARGV idices: ^0 ^1 ^2 ^3 ^4 ^5 ^6
|
/// // ARGV idices: ^0 ^1 ^2 ^3 ^4 ^5 ^6
|
||||||
/// // clap idices: ^2 ^3 ^5 ^6
|
/// // clap idices: ^2 ^3 ^5 ^6
|
||||||
|
|
|
@ -57,10 +57,10 @@ fn index_flags() {
|
||||||
let m = App::new("ind")
|
let m = App::new("ind")
|
||||||
.arg(Arg::with_name("exclude")
|
.arg(Arg::with_name("exclude")
|
||||||
.short("e")
|
.short("e")
|
||||||
.multiple(true))
|
.multiple_occurrences(true))
|
||||||
.arg(Arg::with_name("include")
|
.arg(Arg::with_name("include")
|
||||||
.short("i")
|
.short("i")
|
||||||
.multiple(true))
|
.multiple_occurrences(true))
|
||||||
.get_matches_from(vec!["ind", "-e", "-i", "-e", "-e", "-i"]);
|
.get_matches_from(vec!["ind", "-e", "-i", "-e", "-e", "-i"]);
|
||||||
|
|
||||||
assert_eq!(m.index_of("exclude"), Some(1));
|
assert_eq!(m.index_of("exclude"), Some(1));
|
||||||
|
@ -72,10 +72,10 @@ fn indices_mult_flags() {
|
||||||
let m = App::new("ind")
|
let m = App::new("ind")
|
||||||
.arg(Arg::with_name("exclude")
|
.arg(Arg::with_name("exclude")
|
||||||
.short("e")
|
.short("e")
|
||||||
.multiple(true))
|
.multiple_occurrences(true))
|
||||||
.arg(Arg::with_name("include")
|
.arg(Arg::with_name("include")
|
||||||
.short("i")
|
.short("i")
|
||||||
.multiple(true))
|
.multiple_occurrences(true))
|
||||||
.get_matches_from(vec!["ind", "-e", "-i", "-e", "-e", "-i"]);
|
.get_matches_from(vec!["ind", "-e", "-i", "-e", "-e", "-i"]);
|
||||||
|
|
||||||
assert_eq!(m.indices_of("exclude").unwrap().collect::<Vec<_>>(), &[1, 3, 4]);
|
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")
|
let m = App::new("ind")
|
||||||
.arg(Arg::with_name("exclude")
|
.arg(Arg::with_name("exclude")
|
||||||
.short("e")
|
.short("e")
|
||||||
.multiple(true))
|
.multiple_occurrences(true))
|
||||||
.arg(Arg::with_name("include")
|
.arg(Arg::with_name("include")
|
||||||
.short("i")
|
.short("i")
|
||||||
.multiple(true))
|
.multiple_occurrences(true))
|
||||||
.get_matches_from(vec!["ind", "-eieei"]);
|
.get_matches_from(vec!["ind", "-eieei"]);
|
||||||
|
|
||||||
assert_eq!(m.indices_of("exclude").unwrap().collect::<Vec<_>>(), &[1, 3, 4]);
|
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")
|
let m = App::new("ind")
|
||||||
.arg(Arg::with_name("exclude")
|
.arg(Arg::with_name("exclude")
|
||||||
.short("e")
|
.short("e")
|
||||||
.multiple(true))
|
.multiple_occurrences(true))
|
||||||
.arg(Arg::with_name("include")
|
.arg(Arg::with_name("include")
|
||||||
.short("i")
|
.short("i")
|
||||||
.multiple(true))
|
.multiple_occurrences(true))
|
||||||
.arg(Arg::with_name("option")
|
.arg(Arg::with_name("option")
|
||||||
.short("o")
|
.short("o")
|
||||||
.takes_value(true))
|
.takes_value(true))
|
||||||
|
@ -121,10 +121,10 @@ fn indices_mult_flags_opt_combined_eq() {
|
||||||
let m = App::new("ind")
|
let m = App::new("ind")
|
||||||
.arg(Arg::with_name("exclude")
|
.arg(Arg::with_name("exclude")
|
||||||
.short("e")
|
.short("e")
|
||||||
.multiple(true))
|
.multiple_occurrences(true))
|
||||||
.arg(Arg::with_name("include")
|
.arg(Arg::with_name("include")
|
||||||
.short("i")
|
.short("i")
|
||||||
.multiple(true))
|
.multiple_occurrences(true))
|
||||||
.arg(Arg::with_name("option")
|
.arg(Arg::with_name("option")
|
||||||
.short("o")
|
.short("o")
|
||||||
.takes_value(true))
|
.takes_value(true))
|
||||||
|
@ -164,10 +164,10 @@ fn indices_mult_opt_mult_flag() {
|
||||||
.arg(Arg::with_name("option")
|
.arg(Arg::with_name("option")
|
||||||
.short("o")
|
.short("o")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.multiple(true))
|
.multiple_occurrences(true))
|
||||||
.arg(Arg::with_name("flag")
|
.arg(Arg::with_name("flag")
|
||||||
.short("f")
|
.short("f")
|
||||||
.multiple(true))
|
.multiple_occurrences(true))
|
||||||
.get_matches_from(vec!["myapp", "-o", "val1", "-f", "-o", "val2", "-f"]);
|
.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("option").unwrap().collect::<Vec<_>>(), &[2, 5]);
|
||||||
|
|
Loading…
Reference in a new issue