v0.0.4.10

This commit is contained in:
Kevin K 2015-02-27 11:12:23 -05:00
parent baabac4eea
commit 5515ea064c
3 changed files with 9 additions and 16 deletions

View file

@ -128,18 +128,12 @@ impl App {
if let Some(s) = v.short { if let Some(s) = v.short {
if s != arg { continue; } if s != arg { continue; }
let mut found = false; if !matches.flags.contains_key(k) {
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 {
matches.flags.insert(k, v.clone()); matches.flags.insert(k, v.clone());
} else if matches.flags.get(k).unwrap().multiple {
matches.flags.get_mut(k).unwrap().occurrences += 1
} }
return true; return true;
} }
} }
@ -167,7 +161,6 @@ impl App {
for (k, v) in self.opts.iter() { for (k, v) in self.opts.iter() {
if let Some(ref l) = v.long { if let Some(ref l) = v.long {
if *l == arg { if *l == arg {
found = true;
matches.opts.insert(k, OptArg{ matches.opts.insert(k, OptArg{
name: v.name, name: v.name,
short: v.short, short: v.short,
@ -222,9 +215,10 @@ impl App {
// Multiple flags using short i.e. -bgHlS // Multiple flags using short i.e. -bgHlS
for c in arg.chars() { for c in arg.chars() {
self.check_for_help_and_version(c); 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 { } else {
// Short flag or opt // Short flag or opt
let arg_c = arg.char_at(0); let arg_c = arg.char_at(0);
@ -266,7 +260,6 @@ impl App {
} }
if skip { if skip {
needs_val_of = None; needs_val_of = None;
skip = false;
continue; continue;
} }
if arg_slice.starts_with("--") { if arg_slice.starts_with("--") {

View file

@ -61,7 +61,7 @@ impl Arg {
pub fn multiple(&mut self, multi: bool) -> &mut Arg { pub fn multiple(&mut self, multi: bool) -> &mut Arg {
assert!(self.takes_value == false); assert!(self.takes_value == false);
assert!(self.index == None); assert!(self.index == None);
self.multiple = true; self.multiple = multi;
self self
} }
} }

View file

@ -1,4 +1,4 @@
#![feature(collections, core)] #![feature(collections, core, libc, env)]
pub use argmatches::ArgMatches; pub use argmatches::ArgMatches;
pub use arg::Arg; pub use arg::Arg;