diff --git a/src/parser/arg_matcher.rs b/src/parser/arg_matcher.rs index 04d4189d..c50018c6 100644 --- a/src/parser/arg_matcher.rs +++ b/src/parser/arg_matcher.rs @@ -130,23 +130,22 @@ impl ArgMatcher { pub(crate) fn start_occurrence_of_arg(&mut self, arg: &Arg) { let id = &arg.id; debug!("ArgMatcher::start_occurrence_of_arg: id={:?}", id); - let ma = self.entry(id).or_insert(MatchedArg::new()); + let ma = self.entry(id).or_insert(MatchedArg::new_arg(arg)); ma.set_source(ValueSource::CommandLine); - ma.set_ignore_case(arg.is_ignore_case_set()); ma.inc_occurrences(); } pub(crate) fn start_occurrence_of_group(&mut self, id: &Id) { debug!("ArgMatcher::start_occurrence_of_group: id={:?}", id); - let ma = self.entry(id).or_insert(MatchedArg::new()); + let ma = self.entry(id).or_insert(MatchedArg::new_group()); ma.set_source(ValueSource::CommandLine); ma.inc_occurrences(); } - pub(crate) fn start_occurrence_of_external(&mut self) { + pub(crate) fn start_occurrence_of_external(&mut self, cmd: &crate::Command) { let id = &Id::empty_hash(); debug!("ArgMatcher::start_occurrence_of_external: id={:?}", id,); - let ma = self.entry(id).or_insert(MatchedArg::new()); + let ma = self.entry(id).or_insert(MatchedArg::new_external(cmd)); ma.set_source(ValueSource::CommandLine); ma.inc_occurrences(); } diff --git a/src/parser/matches/matched_arg.rs b/src/parser/matches/matched_arg.rs index 20d8f1d0..a7abf571 100644 --- a/src/parser/matches/matched_arg.rs +++ b/src/parser/matches/matched_arg.rs @@ -22,14 +22,39 @@ pub(crate) struct MatchedArg { } impl MatchedArg { - pub(crate) fn new() -> Self { - MatchedArg { + pub(crate) fn new_arg(arg: &crate::Arg) -> Self { + let ignore_case = arg.is_ignore_case_set(); + Self { occurs: 0, source: None, indices: Vec::new(), vals: Vec::new(), raw_vals: Vec::new(), - ignore_case: false, + ignore_case, + } + } + + pub(crate) fn new_group() -> Self { + let ignore_case = false; + Self { + occurs: 0, + source: None, + indices: Vec::new(), + vals: Vec::new(), + raw_vals: Vec::new(), + ignore_case, + } + } + + pub(crate) fn new_external(_cmd: &crate::Command) -> Self { + let ignore_case = false; + Self { + occurs: 0, + source: None, + indices: Vec::new(), + vals: Vec::new(), + raw_vals: Vec::new(), + ignore_case, } } @@ -146,15 +171,19 @@ impl MatchedArg { self.source = Some(source) } } - - pub(crate) fn set_ignore_case(&mut self, yes: bool) { - self.ignore_case = yes; - } } impl Default for MatchedArg { fn default() -> Self { - Self::new() + let ignore_case = false; + Self { + occurs: 0, + source: None, + indices: Vec::new(), + vals: Vec::new(), + raw_vals: Vec::new(), + ignore_case, + } } } @@ -192,7 +221,7 @@ mod tests { #[test] fn test_grouped_vals_first() { - let mut m = MatchedArg::new(); + let mut m = MatchedArg::new_group(); m.new_val_group(); m.new_val_group(); m.append_val(AnyValue::new(String::from("bbb")), "bbb".into()); @@ -202,7 +231,7 @@ mod tests { #[test] fn test_grouped_vals_push_and_append() { - let mut m = MatchedArg::new(); + let mut m = MatchedArg::new_group(); m.push_val(AnyValue::new(String::from("aaa")), "aaa".into()); m.new_val_group(); m.append_val(AnyValue::new(String::from("bbb")), "bbb".into()); diff --git a/src/parser/parser.rs b/src/parser/parser.rs index c95e5a96..6e525b8f 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -431,7 +431,7 @@ impl<'help, 'cmd> Parser<'help, 'cmd> { // Collect the external subcommand args let mut sc_m = ArgMatcher::new(self.cmd); if cfg!(feature = "unstable-v4") || !raw_args.is_end(&args_cursor) { - sc_m.start_occurrence_of_external(); + sc_m.start_occurrence_of_external(self.cmd); } for raw_val in raw_args.remaining(&mut args_cursor) {