improve getopt parser

This commit is contained in:
Dietmar Maurer 2018-11-18 08:55:21 +01:00
parent a653882dd9
commit 62c40162ee
1 changed files with 9 additions and 5 deletions

View File

@ -78,14 +78,18 @@ pub fn parse_arguments(
_ => (false, false), _ => (false, false),
}; };
if want_bool { let mut next_is_argument = false;
let mut next_is_bool = false;
let mut next_is_bool = false; if (pos + 1) < args.len() {
if (pos + 1) < args.len() { let next = &args[pos+1];
let next = &args[pos+1]; if let RawArgument::Argument { value: _} = parse_argument(next) {
next_is_argument = true;
if let Ok(_) = parse_boolean(next) { next_is_bool = true; } if let Ok(_) = parse_boolean(next) { next_is_bool = true; }
} }
}
if want_bool {
if next_is_bool { if next_is_bool {
pos += 1; pos += 1;
data.push((name, args[pos].clone())); data.push((name, args[pos].clone()));
@ -98,7 +102,7 @@ pub fn parse_arguments(
} else { } else {
if (pos + 1) < args.len() { if next_is_argument {
pos += 1; pos += 1;
data.push((name, args[pos].clone())); data.push((name, args[pos].clone()));
} else { } else {