Skip to content

Commit

Permalink
refactor(parser): Clarify intent for defaults/envs
Browse files Browse the repository at this point in the history
Especially important is not inferring intent from occurrences as
hopefully that will change with the introduction of actions.
  • Loading branch information
epage committed May 27, 2022
1 parent 2a409be commit 8f16f2e
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,10 +1119,7 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
for arg in self.cmd.get_arguments() {
// Use env only if the arg was absent among command line args,
// early return if this is not the case.
if matcher
.get(&arg.id)
.map_or(false, |arg| arg.get_occurrences() != 0)
{
if matcher.contains(&arg.id) {
debug!("Parser::add_env: Skipping existing arg `{}`", arg);
continue;
}
Expand Down Expand Up @@ -1231,7 +1228,7 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {

if !arg.default_vals_ifs.is_empty() {
debug!("Parser::add_default_value: has conditional defaults");
if matcher.get(&arg.id).is_none() {
if !matcher.contains(&arg.id) {
for (id, val, default) in arg.default_vals_ifs.iter() {
let add = if let Some(a) = matcher.get(id) {
match val {
Expand Down Expand Up @@ -1270,7 +1267,7 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
"Parser::add_default_value:iter:{}: has default vals",
arg.name
);
if matcher.get(&arg.id).is_some() {
if matcher.contains(&arg.id) {
debug!("Parser::add_default_value:iter:{}: was used", arg.name);
// do nothing
} else {
Expand Down

0 comments on commit 8f16f2e

Please sign in to comment.