mirror of
https://github.com/clap-rs/clap
synced 2024-09-21 06:41:54 +00:00
v0.0.4.10
This commit is contained in:
parent
baabac4eea
commit
5515ea064c
3 changed files with 9 additions and 16 deletions
21
src/app.rs
21
src/app.rs
|
@ -128,18 +128,12 @@ impl App {
|
|||
if let Some(s) = v.short {
|
||||
if s != arg { continue; }
|
||||
|
||||
let mut found = false;
|
||||
if let Some(ref mut f) = matches.flags.get_mut(k) {
|
||||
f.occurrences = if f.multiple { f.occurrences + 1 } else { 1 };
|
||||
found = true;
|
||||
}
|
||||
|
||||
// Cannot borrow mutable twice at same time
|
||||
// so the if let must finish it's scope first
|
||||
// before calling .insert()
|
||||
if ! found {
|
||||
if !matches.flags.contains_key(k) {
|
||||
matches.flags.insert(k, v.clone());
|
||||
} else if matches.flags.get(k).unwrap().multiple {
|
||||
matches.flags.get_mut(k).unwrap().occurrences += 1
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -167,7 +161,6 @@ impl App {
|
|||
for (k, v) in self.opts.iter() {
|
||||
if let Some(ref l) = v.long {
|
||||
if *l == arg {
|
||||
found = true;
|
||||
matches.opts.insert(k, OptArg{
|
||||
name: v.name,
|
||||
short: v.short,
|
||||
|
@ -222,9 +215,10 @@ impl App {
|
|||
// Multiple flags using short i.e. -bgHlS
|
||||
for c in arg.chars() {
|
||||
self.check_for_help_and_version(c);
|
||||
if self.parse_single_short_flag(matches, c) { return None }
|
||||
if ! self.parse_single_short_flag(matches, c) {
|
||||
panic!("Argument -{} isn't valid",arg);
|
||||
}
|
||||
}
|
||||
panic!("Argument -{} isn't valid",arg);
|
||||
} else {
|
||||
// Short flag or opt
|
||||
let arg_c = arg.char_at(0);
|
||||
|
@ -266,7 +260,6 @@ impl App {
|
|||
}
|
||||
if skip {
|
||||
needs_val_of = None;
|
||||
skip = false;
|
||||
continue;
|
||||
}
|
||||
if arg_slice.starts_with("--") {
|
||||
|
|
|
@ -61,7 +61,7 @@ impl Arg {
|
|||
pub fn multiple(&mut self, multi: bool) -> &mut Arg {
|
||||
assert!(self.takes_value == false);
|
||||
assert!(self.index == None);
|
||||
self.multiple = true;
|
||||
self.multiple = multi;
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
#![feature(collections, core)]
|
||||
#![feature(collections, core, libc, env)]
|
||||
|
||||
pub use argmatches::ArgMatches;
|
||||
pub use arg::Arg;
|
||||
|
|
Loading…
Reference in a new issue