Skip to content

Commit

Permalink
fix(option args): fix bug in getting the wrong number of occurrences …
Browse files Browse the repository at this point in the history
…for options
  • Loading branch information
kbknapp committed Apr 2, 2015
1 parent 7cf9659 commit 82ad6ad
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ impl<'a, 'v, 'ab, 'u, 'ar> App<'a, 'v, 'ab, 'u, 'ar>{
if let Some(ref mut o) = matches.opts.get_mut(opt.name) {
o.values.push(arg.clone());
// if it's multiple the occurrences are increased when originall found
o.occurrences = if opt.multiple { o.occurrences } else { 1 };
o.occurrences = if opt.multiple { o.occurrences + 1 } else { 1 };
}

skip = true;
Expand Down Expand Up @@ -941,7 +941,7 @@ impl<'a, 'v, 'ab, 'u, 'ar> App<'a, 'v, 'ab, 'u, 'ar>{
} else {
matches.opts.insert(v.name, OptArg{
name: v.name.to_owned(),
occurrences: 1,
occurrences: if arg_val.is_some() { 1 } else { 0 },
values: if arg_val.is_some() { vec![arg_val.clone().unwrap()]} else {vec![]}
});
}
Expand Down Expand Up @@ -1066,7 +1066,8 @@ impl<'a, 'v, 'ab, 'u, 'ar> App<'a, 'v, 'ab, 'u, 'ar>{
} else {
matches.opts.insert(v.name, OptArg{
name: v.name.to_owned(),
occurrences: 1,
// occurrences will be incremented on getting a value
occurrences: 0,
values: vec![]
});
}
Expand Down

0 comments on commit 82ad6ad

Please sign in to comment.