refactor: Allow more conflicts to be reported

This commit is contained in:
Ed Page 2021-12-23 11:18:22 -06:00
parent f24b9f50de
commit 02f4ff2115
2 changed files with 25 additions and 19 deletions

View file

@ -549,35 +549,41 @@ impl Error {
pub(crate) fn argument_conflict(
app: &App,
arg: &Arg,
other: Option<String>,
others: Vec<String>,
usage: String,
) -> Self {
let mut c = Colorizer::new(true, app.get_color());
let arg = arg.to_string();
start_error(&mut c, "The argument '");
c.warning(arg.clone());
c.none("' cannot be used with ");
c.warning(arg);
c.none("' cannot be used with");
match other {
Some(ref name) => {
c.none("'");
c.warning(name);
c.none("'");
let mut info = vec![];
match others.len() {
0 => {
c.none(" one or more of the other specified arguments");
}
None => {
c.none("one or more of the other specified arguments");
1 => {
let v = &others[0];
c.none(" '");
c.warning(v.clone());
c.none("'");
info.push(v.clone());
}
};
_ => {
c.none(":");
for v in others {
c.none("\n ");
c.warning(v.to_string());
info.push(v.to_string());
}
}
}
put_usage(&mut c, usage);
try_help(app, &mut c);
let mut info = vec![arg];
if let Some(other) = other {
info.push(other);
}
Self::new(
c,
ErrorKind::ArgumentConflict,

View file

@ -224,7 +224,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> {
Err(Error::argument_conflict(
self.p.app,
latter_arg,
Some(former_arg.to_string()),
vec![former_arg.to_string()],
usg,
))
})
@ -243,7 +243,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> {
Err(Error::argument_conflict(
self.p.app,
&self.p.app[first],
c_with,
c_with.into_iter().collect(),
usg,
))
} else {
@ -319,7 +319,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> {
Err(Error::argument_conflict(
self.p.app,
arg,
None,
Vec::new(),
Usage::new(self.p).create_usage_with_title(&[]),
))
})