Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(parser): Prep for more #2688 work #4024

Merged
merged 3 commits into from Aug 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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