mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 14:54:15 +00:00
Add test for three argument conflict output
This commit is contained in:
parent
6602feb9e6
commit
826db05319
2 changed files with 41 additions and 5 deletions
|
@ -183,18 +183,21 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> {
|
|||
(k, a, name, checked_arg)
|
||||
}
|
||||
};
|
||||
let used: Vec<Id> = matcher
|
||||
let former_blacklist = &former_arg.blacklist;
|
||||
let used_filtered: Vec<Id> = matcher
|
||||
.arg_names()
|
||||
.filter(|key| *key != latter)
|
||||
.filter(|key| !former_blacklist.contains(key))
|
||||
.cloned()
|
||||
.collect();
|
||||
let required: Vec<Id> = used
|
||||
let required: Vec<Id> = used_filtered
|
||||
.iter()
|
||||
.filter_map(|key| self.p.app.find(key))
|
||||
.flat_map(|key_arg| key_arg.requires.iter().map(|item| &item.1))
|
||||
.filter(|item| !used.contains(item))
|
||||
.filter(|item| !used_filtered.contains(item))
|
||||
.filter(|key| *key != latter)
|
||||
.chain(used.iter())
|
||||
.filter(|key| !former_blacklist.contains(key))
|
||||
.chain(used_filtered.iter())
|
||||
.cloned()
|
||||
.collect();
|
||||
println!("{:?}", required);
|
||||
|
|
|
@ -16,6 +16,13 @@ USAGE:
|
|||
|
||||
For more information try --help";
|
||||
|
||||
static CONFLICT_ERR_THREE: &str = "error: The argument '--one' cannot be used with '--two'
|
||||
|
||||
USAGE:
|
||||
three_conflicting_arguments --one
|
||||
|
||||
For more information try --help";
|
||||
|
||||
#[test]
|
||||
fn flag_conflict() {
|
||||
let result = App::new("flag_conflict")
|
||||
|
@ -126,6 +133,32 @@ fn conflict_output_rev_with_required() {
|
|||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn conflict_output_three_conflicting() {
|
||||
let app = App::new("three_conflicting_arguments")
|
||||
.arg(
|
||||
Arg::new("one")
|
||||
.long("one")
|
||||
.conflicts_with_all(&["two", "three"]),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("two")
|
||||
.long("two")
|
||||
.conflicts_with_all(&["one", "three"]),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("three")
|
||||
.long("three")
|
||||
.conflicts_with_all(&["one", "two"]),
|
||||
);
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"three_conflicting_arguments --one --two --three",
|
||||
CONFLICT_ERR_THREE,
|
||||
true,
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn conflict_with_unused_default_value() {
|
||||
let result = App::new("conflict")
|
||||
|
@ -163,7 +196,7 @@ fn two_conflicting_arguments() {
|
|||
|
||||
#[test]
|
||||
fn three_conflicting_arguments() {
|
||||
let a = App::new("two_conflicting_arguments")
|
||||
let a = App::new("three_conflicting_arguments")
|
||||
.arg(
|
||||
Arg::new("one")
|
||||
.long("one")
|
||||
|
|
Loading…
Reference in a new issue