From 62c40162ee843ecb9a3788ce5319f686638fe26f Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sun, 18 Nov 2018 08:55:21 +0100 Subject: [PATCH] improve getopt parser --- src/getopts.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/getopts.rs b/src/getopts.rs index 58e77271..81aacbc5 100644 --- a/src/getopts.rs +++ b/src/getopts.rs @@ -78,14 +78,18 @@ pub fn parse_arguments( _ => (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() { - let next = &args[pos+1]; + if (pos + 1) < args.len() { + 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 want_bool { if next_is_bool { pos += 1; data.push((name, args[pos].clone())); @@ -98,7 +102,7 @@ pub fn parse_arguments( } else { - if (pos + 1) < args.len() { + if next_is_argument { pos += 1; data.push((name, args[pos].clone())); } else {