diff --git a/src/app/mod.rs b/src/app/mod.rs index 34d24c0a..6fe3d228 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -1621,8 +1621,6 @@ impl<'a, 'b> App<'a, 'b> { } if self.p.is_set(AppSettings::PropagateGlobalValuesDown) { - // TODO: get a list of all the argument names, create a vector - // from it, and passing that to propagate. let global_arg_vec : Vec<&str> = (&self).p.global_args.iter().map(|ga| ga.b.name).collect(); let mut global_arg_to_value_map = HashMap::new(); matcher.get_global_values(&global_arg_vec, &mut global_arg_to_value_map); diff --git a/src/app/parser.rs b/src/app/parser.rs index 54e7f957..804e9aae 100644 --- a/src/app/parser.rs +++ b/src/app/parser.rs @@ -1072,10 +1072,7 @@ impl<'a, 'b> Parser<'a, 'b> info: None, }); } - // FIXME: this makes the globals exist more than once - // if self.settings.is_set(AS::PropagateGlobalValuesDown) { - // self.propogate_globals(); - // } + Validator::new(self).validate(needs_val_of, subcmd_name, matcher) } diff --git a/src/args/arg_matcher.rs b/src/args/arg_matcher.rs index 9fe36015..b8433303 100644 --- a/src/args/arg_matcher.rs +++ b/src/args/arg_matcher.rs @@ -22,96 +22,18 @@ impl<'a> Default for ArgMatcher<'a> { impl<'a> ArgMatcher<'a> { pub fn new() -> Self { ArgMatcher::default() } - // TODO: maybe this would work better as a while loop - // than as a recursive call, so that we can push subcommands - // onto a stack and gather values from them as we go, then - // pop the stack and set values as needed pub fn get_global_values(&mut self, global_arg_vec : &Vec<&'a str>, vals_map: &mut HashMap<&'a str, Vec>) { for global_arg in global_arg_vec.iter() { let vals: Vec<_> = if let Some(ma) = self.get(global_arg) { ma.vals.clone() } else { debugln!("ArgMatcher::propagate: arg wasn't used"); - //return; // we can't return early because some subcommand might - // TODO: can we start returning early again if we Vec::new() }; vals_map.insert(global_arg, vals); } } - - // pub fn propagate_globals(&mut self, global_arg_vec: Vec<&'a str>) { - // debugln!("ArgMatcher::propagate: arg={}", arg); - // // we need to decide which subcommands were actually used by asking - // // each successive subcommand for the next subcommand - // let mut subcommand_stack : Vec> = vec![]; - - - // //let mut am : &mut ArgMatcher; - // if let Some(ref mut sc) = self.0.subcommand { - // let mut found_subcommand = sc.clone(); - // let mut unboxed_sub : SubCommand = *found_subcommand; - // subcommand_stack.push(Box::new(unboxed_sub.clone())); - // let mut option_sub = unboxed_sub.matches.subcommand().1; - // while let Some(ref mut new_arg_matches) = option_sub { - // if let Some(ref new_subcommand) = new_arg_matches.subcommand { - // subcommand_stack.push(Box::new(*new_subcommand.clone())); - // option_sub = Some(&new_subcommand.matches); - // } - // } - // } - // // TODO make a new matcher and propagate - // for boxed_sub in subcommand_stack.iter() { - // let mut unboxed_sub = &*boxed_sub; - // let mut ix: usize = 0; - // for global_arg in global_arg_vec.iter() { - // let vals = &vals_vec[ix]; - - // let sma = (unboxed_sub).matches.args.entry(global_arg).or_insert_with(|| { - // let mut gma = MatchedArg::new(); - // gma.occurs += 1; - // if !vals.is_empty() { - // gma.vals = *vals.clone(); - // } - // gma - // }); - // if sma.vals.is_empty() { - // sma.vals = *vals.clone(); - // } - // ix += 1; - // } - - // //let mut am = //&mut ArgMatcher(mem::replace(&mut sc.matches, ArgMatches::new())); - // let mut am = ArgMatcher(ArgMatches::new()); - // mem::swap(&mut am.0, &mut unboxed_sub.matches); - // } - - // // for arg in global_arg_vec { - - // // if let Some(ref mut sc) = self.0.subcommand { - // // { - // // let sma = (*sc).matches.args.entry(arg).or_insert_with(|| { - // // let mut gma = MatchedArg::new(); - // // gma.occurs += 1; - // // if !vals.is_empty() { - // // gma.vals = vals.clone(); - // // } - // // gma - // // }); - // // if sma.vals.is_empty() { - // // sma.vals = vals.clone(); - // // } - // // } - // // let mut am = ArgMatcher(mem::replace(&mut sc.matches, ArgMatches::new())); - // // am.propagate(global_arg_vec.clone()); - // // mem::swap(&mut am.0, &mut sc.matches); - // // } else { - // // debugln!("ArgMatcher::propagate: Subcommand wasn't used"); - // // } - // // } - // } - pub fn get_mut(&mut self, arg: &str) -> Option<&mut MatchedArg> { self.0.args.get_mut(arg) } pub fn get(&self, arg: &str) -> Option<&MatchedArg> { self.0.args.get(arg) }