Merge pull request #3973 from epage/help-env

fix(env)!: Parse help/version like normal
This commit is contained in:
Ed Page 2022-07-22 13:23:06 -05:00 committed by GitHub
commit d162b846ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 6 deletions

View file

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- `ErrorKind::EmptyValue` replaced with `ErrorKind::InvalidValue`
- `ErrorKind::UnrecognizedSubcommand` replaced with `ErrorKind::InvalidSubcommand`
- *(env)* Parse `--help` and `--version` like any `ArgAction::SetTrue` flag
- *(derive)* `subcommand_required(true).arg_required_else_help(true)` is set instead of `SubcommandRequiredElseHelp`
### Features

View file

@ -1395,7 +1395,9 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
| ArgAction::Append
| ArgAction::SetTrue
| ArgAction::SetFalse
| ArgAction::Count => {
| ArgAction::Count
| ArgAction::Help
| ArgAction::Version => {
let mut arg_values = Vec::new();
let _parse_result =
self.split_arg_values(arg, &val, trailing_values, &mut arg_values);
@ -1412,11 +1414,6 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
}
}
}
// Early return on `Help` or `Version`.
ArgAction::Help | ArgAction::Version => {
let _ =
self.react(None, ValueSource::EnvVariable, arg, vec![], matcher)?;
}
}
}
}