mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
Arg names, shorts, and longs must now be unique
This commit is contained in:
parent
be61ff9842
commit
1c752d38d1
1 changed files with 10 additions and 6 deletions
16
src/app.rs
16
src/app.rs
|
@ -51,6 +51,8 @@ pub struct App {
|
||||||
needs_short_version: bool,
|
needs_short_version: bool,
|
||||||
required: HashSet<&'static str>,
|
required: HashSet<&'static str>,
|
||||||
arg_list: HashSet<&'static str>,
|
arg_list: HashSet<&'static str>,
|
||||||
|
short_list: HashSet<char>,
|
||||||
|
long_list: HashSet<&'static str>,
|
||||||
blacklist: HashSet<&'static str>,
|
blacklist: HashSet<&'static str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +81,8 @@ impl App {
|
||||||
needs_short_version: true,
|
needs_short_version: true,
|
||||||
required: HashSet::new(),
|
required: HashSet::new(),
|
||||||
arg_list: HashSet::new(),
|
arg_list: HashSet::new(),
|
||||||
|
short_list: HashSet::new(),
|
||||||
|
long_list: HashSet::new(),
|
||||||
blacklist: HashSet::new(),
|
blacklist: HashSet::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,18 +138,18 @@ impl App {
|
||||||
} else {
|
} else {
|
||||||
self.arg_list.insert(a.name);
|
self.arg_list.insert(a.name);
|
||||||
}
|
}
|
||||||
if let Some(s) = a.short {
|
if let Some(ref s) = a.short {
|
||||||
if self.arg_list.contains(s) {
|
if self.short_list.contains(s) {
|
||||||
panic!("Argument short must be unique, -{} is already in use", s);
|
panic!("Argument short must be unique, -{} is already in use", s);
|
||||||
} else {
|
} else {
|
||||||
self.arg_list.insert(s);
|
self.short_list.insert(*s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(l) = a.long {
|
if let Some(ref l) = a.long {
|
||||||
if self.arg_list.contains(l) {
|
if self.long_list.contains(l) {
|
||||||
panic!("Argument long must be unique, --{} is already in use", l);
|
panic!("Argument long must be unique, --{} is already in use", l);
|
||||||
} else {
|
} else {
|
||||||
self.arg_list.insert(l);
|
self.long_list.insert(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if a.required {
|
if a.required {
|
||||||
|
|
Loading…
Reference in a new issue