mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 23:04:23 +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,
|
||||
required: HashSet<&'static str>,
|
||||
arg_list: HashSet<&'static str>,
|
||||
short_list: HashSet<char>,
|
||||
long_list: HashSet<&'static str>,
|
||||
blacklist: HashSet<&'static str>,
|
||||
}
|
||||
|
||||
|
@ -79,6 +81,8 @@ impl App {
|
|||
needs_short_version: true,
|
||||
required: HashSet::new(),
|
||||
arg_list: HashSet::new(),
|
||||
short_list: HashSet::new(),
|
||||
long_list: HashSet::new(),
|
||||
blacklist: HashSet::new(),
|
||||
}
|
||||
}
|
||||
|
@ -134,18 +138,18 @@ impl App {
|
|||
} else {
|
||||
self.arg_list.insert(a.name);
|
||||
}
|
||||
if let Some(s) = a.short {
|
||||
if self.arg_list.contains(s) {
|
||||
if let Some(ref s) = a.short {
|
||||
if self.short_list.contains(s) {
|
||||
panic!("Argument short must be unique, -{} is already in use", s);
|
||||
} else {
|
||||
self.arg_list.insert(s);
|
||||
self.short_list.insert(*s);
|
||||
}
|
||||
}
|
||||
if let Some(l) = a.long {
|
||||
if self.arg_list.contains(l) {
|
||||
if let Some(ref l) = a.long {
|
||||
if self.long_list.contains(l) {
|
||||
panic!("Argument long must be unique, --{} is already in use", l);
|
||||
} else {
|
||||
self.arg_list.insert(l);
|
||||
self.long_list.insert(l);
|
||||
}
|
||||
}
|
||||
if a.required {
|
||||
|
|
Loading…
Reference in a new issue