From ff8ea640e9441c977db52f915f2d50f27e78c2ef Mon Sep 17 00:00:00 2001 From: Kevin K Date: Wed, 18 Mar 2015 10:15:55 -0400 Subject: [PATCH] Moved some for loops to more readable iterators --- src/app.rs | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/app.rs b/src/app.rs index 83012c1c..abbc4366 100644 --- a/src/app.rs +++ b/src/app.rs @@ -526,12 +526,15 @@ impl App { } if let Some(ref reqs) = v.requires { if ! reqs.is_empty() { - for n in reqs.iter() { - if matches.opts.contains_key(n) { continue; } - if matches.flags.contains_key(n) { continue; } - if matches.positionals.contains_key(n) { continue; } - self.required.insert(n); - } + // Add all required args which aren't already found in matches to the + // final required list + for n in reqs.iter().filter(|&a| + ! matches.opts.contains_key(a) || + ! matches.flags.contains_key(a) || + ! matches.positionals.contains_key(a) ) { + + self.required.insert(n); + } } } break; @@ -744,13 +747,16 @@ impl App { } if let Some(ref reqs) = opt.requires { if ! reqs.is_empty() { - for n in reqs.iter() { - if matches.opts.contains_key(n) { continue; } - if matches.flags.contains_key(n) { continue; } - if matches.positionals.contains_key(n) { continue; } - self.required.insert(n); - } - } + // Add all required args which aren't already found in matches to the + // final required list + for n in reqs.iter().filter(|&a| + ! matches.opts.contains_key(a) || + ! matches.flags.contains_key(a) || + ! matches.positionals.contains_key(a) ) { + + self.required.insert(n); + } + } } skip = true; } @@ -810,11 +816,14 @@ impl App { } if let Some(ref reqs) = p.requires { if ! reqs.is_empty() { - for n in reqs.iter() { - if matches.opts.contains_key(n) { continue; } - if matches.flags.contains_key(n) { continue; } - if matches.positionals.contains_key(n) { continue; } - self.required.insert(n); + // Add all required args which aren't already found in matches to the + // final required list + for n in reqs.iter().filter(|&a| + ! matches.opts.contains_key(a) || + ! matches.flags.contains_key(a) || + ! matches.positionals.contains_key(a) ) { + + self.required.insert(n); } } }