mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 23:37:32 +00:00
refactor: Allow more conflicts to be reported
This commit is contained in:
parent
f24b9f50de
commit
02f4ff2115
2 changed files with 25 additions and 19 deletions
|
@ -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,
|
||||
|
|
|
@ -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(&[]),
|
||||
))
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue