Skip to content

Commit

Permalink
Merge pull request #4024 from epage/cleanup
Browse files Browse the repository at this point in the history
refactor(parser): Prep for more #2688 work
  • Loading branch information
epage committed Aug 4, 2022
2 parents 012de8d + 53836f5 commit b731b6a
Showing 1 changed file with 12 additions and 30 deletions.
42 changes: 12 additions & 30 deletions src/parser/parser.rs
Expand Up @@ -134,7 +134,6 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
long_value,
&parse_state,
&mut valid_arg_found,
trailing_values,
)?;
debug!(
"Parser::get_matches_with: After parse_long_arg {:?}",
Expand Down Expand Up @@ -204,7 +203,6 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
&parse_state,
pos_counter,
&mut valid_arg_found,
trailing_values,
)?;
// If it's None, we then check if one of those two AppSettings was set
debug!(
Expand Down Expand Up @@ -278,6 +276,7 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
// get the option so we can check the settings
let arg_values = matcher.pending_values_mut(id, None);
let arg = &self.cmd[id];
let trailing_values = false;
let parse_result = self.split_arg_values(
arg,
arg_os.to_value_os(),
Expand Down Expand Up @@ -711,7 +710,6 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
long_value: Option<&RawOsStr>,
parse_state: &ParseState,
valid_arg_found: &mut bool,
trailing_values: bool,
) -> ClapResult<ParseResult> {
// maybe here lifetime should be 'a
debug!("Parser::parse_long_arg");
Expand Down Expand Up @@ -768,7 +766,7 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
long_arg, &long_value
);
let has_eq = long_value.is_some();
self.parse_opt_value(ident, long_value, arg, matcher, trailing_values, has_eq)
self.parse_opt_value(ident, long_value, arg, matcher, has_eq)
} else if let Some(rest) = long_value {
let required = self.cmd.required_graph();
debug!(
Expand Down Expand Up @@ -816,7 +814,6 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
// change this to possible pos_arg when removing the usage of &mut Parser.
pos_counter: usize,
valid_arg_found: &mut bool,
trailing_values: bool,
) -> ClapResult<ParseResult> {
debug!("Parser::parse_short_arg: short_arg={:?}", short_arg);

Expand Down Expand Up @@ -912,7 +909,7 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
} else {
(val, false)
};
match self.parse_opt_value(ident, val, arg, matcher, trailing_values, has_eq)? {
match self.parse_opt_value(ident, val, arg, matcher, has_eq)? {
ParseResult::AttachedValueNotConsumed => continue,
x => return Ok(x),
}
Expand Down Expand Up @@ -951,7 +948,6 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
attached_value: Option<&RawOsStr>,
arg: &Arg<'help>,
matcher: &mut ArgMatcher,
trailing_values: bool,
has_eq: bool,
) -> ClapResult<ParseResult> {
debug!(
Expand Down Expand Up @@ -987,6 +983,7 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
}
} else if let Some(v) = attached_value {
let mut arg_values = Vec::new();
let trailing_values = false;
let parse_result = self.split_arg_values(arg, v, trailing_values, &mut arg_values);
let react_result = self.react(
Some(ident),
Expand Down Expand Up @@ -1354,29 +1351,14 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
if let Some((_, Some(ref val))) = arg.env {
let val = RawOsStr::new(val);

if arg.is_takes_value_set() {
debug!(
"Parser::add_env: Found an opt with value={:?}, trailing={:?}",
val, trailing_values
);
let mut arg_values = Vec::new();
let _parse_result =
self.split_arg_values(arg, &val, trailing_values, &mut arg_values);
let _ = self.react(None, ValueSource::EnvVariable, arg, arg_values, matcher)?;
if let Some(_parse_result) = _parse_result {
if _parse_result != ParseResult::ValuesDone {
debug!("Parser::add_env: Ignoring state {:?}; env variables are outside of the parse loop", _parse_result);
}
}
} else {
let mut arg_values = Vec::new();
let _parse_result =
self.split_arg_values(arg, &val, trailing_values, &mut arg_values);
let _ = self.react(None, ValueSource::EnvVariable, arg, arg_values, matcher)?;
if let Some(_parse_result) = _parse_result {
if _parse_result != ParseResult::ValuesDone {
debug!("Parser::add_env: Ignoring state {:?}; env variables are outside of the parse loop", _parse_result);
}
debug!("Parser::add_env: Found an opt with value={:?}", val,);
let mut arg_values = Vec::new();
let _parse_result =
self.split_arg_values(arg, &val, trailing_values, &mut arg_values);
let _ = self.react(None, ValueSource::EnvVariable, arg, arg_values, matcher)?;
if let Some(_parse_result) = _parse_result {
if _parse_result != ParseResult::ValuesDone {
debug!("Parser::add_env: Ignoring state {:?}; env variables are outside of the parse loop", _parse_result);
}
}
}
Expand Down

0 comments on commit b731b6a

Please sign in to comment.