refactor(app::Parser) Replace continue and .push() with iterator adaptors

This commit is contained in:
tormol 2016-10-04 18:45:35 +02:00
parent 9679713a30
commit a214a34529

View file

@ -353,33 +353,23 @@ impl<'a, 'b> Parser<'a, 'b>
c_flags.dedup(); c_flags.dedup();
c_opt.dedup(); c_opt.dedup();
grps.dedup(); grps.dedup();
let mut args_in_groups = vec![]; let args_in_groups = grps.iter()
for g in &grps { .flat_map(|g| self.arg_names_in_group(g) )
for a in self.arg_names_in_group(g) { .collect::<Vec<_>>();
args_in_groups.push(a);
}
}
let mut pmap = BTreeMap::new(); let pmap = c_pos.into_iter()
for p in c_pos { .filter(|&p| matcher.is_none() || !matcher.as_ref().unwrap().contains(p) )
if matcher.is_some() && matcher.as_ref().unwrap().contains(p) { .filter_map(|p| self.positionals.values().find(|x| x.name == p ) )
continue; .filter(|p| !args_in_groups.contains(&p.name) )
} .map(|p| (p.index, p) )
if let Some(p) = self.positionals.values().find(|x| &x.name == &p) { .collect::<BTreeMap<u64,&PosBuilder>>();// sort by index
if args_in_groups.contains(&p.name) {
continue;
}
pmap.insert(p.index, p.to_string());
}
}
debugln!("args_in_groups={:?}", args_in_groups); debugln!("args_in_groups={:?}", args_in_groups);
for (_, s) in pmap { for &p in pmap.values() {
if (!args_in_groups.is_empty()) && (args_in_groups.contains(&&*s)) { let s = p.to_string();
continue; if args_in_groups.is_empty() || !args_in_groups.contains(&&*s) {
}
ret_val.push_back(s); ret_val.push_back(s);
} }
}
macro_rules! write_arg { macro_rules! write_arg {
($i:expr, $m:ident, $v:ident, $r:ident, $aig:ident) => { ($i:expr, $m:ident, $v:ident, $r:ident, $aig:ident) => {
for f in $v { for f in $v {