Revert "Revert "Added ArgMatcher::is_default_value abstraction""

This reverts commit 5e76e6c568.
This commit is contained in:
Pavan Kumar Sunkara 2021-11-03 18:52:19 +00:00
parent 45f281b67e
commit 6b458c602d
2 changed files with 7 additions and 4 deletions

View file

@ -126,6 +126,11 @@ impl ArgMatcher {
self.0.args.iter() self.0.args.iter()
} }
pub(crate) fn is_default_value(&self, arg: &Id) -> bool {
self.get(arg)
.map_or(false, |a| a.ty == ValueType::DefaultValue)
}
pub(crate) fn inc_occurrence_of(&mut self, arg: &Id, ci: bool) { pub(crate) fn inc_occurrence_of(&mut self, arg: &Id, ci: bool) {
debug!("ArgMatcher::inc_occurrence_of: arg={:?}", arg); debug!("ArgMatcher::inc_occurrence_of: arg={:?}", arg);
let ma = self.entry(arg).or_insert(MatchedArg::new()); let ma = self.entry(arg).or_insert(MatchedArg::new());

View file

@ -4,7 +4,7 @@ use crate::{
output::Usage, output::Usage,
parse::{ parse::{
errors::{Error, ErrorKind, Result as ClapResult}, errors::{Error, ErrorKind, Result as ClapResult},
ArgMatcher, MatchedArg, ParseState, Parser, ValueType, ArgMatcher, MatchedArg, ParseState, Parser,
}, },
util::{ChildGraph, Id}, util::{ChildGraph, Id},
INTERNAL_ERROR_MSG, INVALID_UTF8, INTERNAL_ERROR_MSG, INVALID_UTF8,
@ -338,9 +338,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> {
debug!("Validator::gather_conflicts:iter: id={:?}", name); debug!("Validator::gather_conflicts:iter: id={:?}", name);
// if arg is "present" only because it got default value // if arg is "present" only because it got default value
// it doesn't conflict with anything and should be skipped // it doesn't conflict with anything and should be skipped
let skip = matcher let skip = matcher.is_default_value(name);
.get(name)
.map_or(false, |a| a.ty == ValueType::DefaultValue);
if skip { if skip {
debug!("Validator::gather_conflicts:iter: This is default value, skipping.",); debug!("Validator::gather_conflicts:iter: This is default value, skipping.",);
} }