mirror of
https://github.com/clap-rs/clap
synced 2024-09-20 14:31:58 +00:00
v0.3.3
This commit is contained in:
parent
d5369ee1c0
commit
8ee4e2dca5
2 changed files with 52 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
|
||||
name = "clap"
|
||||
version = "0.3.0"
|
||||
version = "0.3.3"
|
||||
authors = ["Kevin K. <kbknapp@gmail.com>"]
|
||||
|
|
53
src/app.rs
53
src/app.rs
|
@ -26,7 +26,7 @@ pub struct App {
|
|||
needs_short_version: bool,
|
||||
required: HashSet<&'static str>,
|
||||
arg_list: HashSet<&'static str>,
|
||||
blacklist: HashSet<&'static str>
|
||||
blacklist: HashSet<&'static str>,
|
||||
}
|
||||
|
||||
impl App {
|
||||
|
@ -46,7 +46,7 @@ impl App {
|
|||
needs_short_version: true,
|
||||
required: HashSet::new(),
|
||||
arg_list: HashSet::new(),
|
||||
blacklist: HashSet::new()
|
||||
blacklist: HashSet::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -399,6 +399,52 @@ impl App {
|
|||
None
|
||||
}
|
||||
|
||||
fn validate_blacklist(&self, matches: &ArgMatches) {
|
||||
if ! self.blacklist.is_empty() {
|
||||
for name in self.blacklist.iter() {
|
||||
for (k, v) in matches.flags.iter() {
|
||||
if k == name {
|
||||
self.report_error(&format!("The argument \"{}\" is mutually exclusive with one or more other arguments",
|
||||
if let Some(s) = v.short {
|
||||
format!("-{}", s)
|
||||
} else if let Some(l) = v.long {
|
||||
format!("--{}", l)
|
||||
} else {
|
||||
format!("{}", v.name)
|
||||
}),
|
||||
false, true);
|
||||
}
|
||||
}
|
||||
for (k, v) in matches.opts.iter() {
|
||||
if k == name {
|
||||
self.report_error(&format!("The argument \"{}\" is mutually exclusive with one or more other arguments",
|
||||
if let Some(s) = v.short {
|
||||
format!("-{}", s)
|
||||
} else if let Some(l) = v.long {
|
||||
format!("--{}", l)
|
||||
} else {
|
||||
format!("{}", v.name)
|
||||
}),
|
||||
false, true);
|
||||
}
|
||||
}
|
||||
for (k, v) in matches.positionals.iter() {
|
||||
if k == name {
|
||||
self.report_error(&format!("The argument \"{}\" is mutually exclusive with one or more other arguments",
|
||||
if let Some(s) = v.short {
|
||||
format!("-{}", s)
|
||||
} else if let Some(l) = v.long {
|
||||
format!("--{}", l)
|
||||
} else {
|
||||
format!("{}", v.name)
|
||||
}),
|
||||
false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_matches(&mut self) -> ArgMatches {
|
||||
let mut matches = ArgMatches::new(self);
|
||||
|
||||
|
@ -523,6 +569,9 @@ impl App {
|
|||
self.report_error(&"One or more required arguments were not supplied".to_string(),
|
||||
false, true);
|
||||
}
|
||||
|
||||
self.validate_blacklist(&matches);
|
||||
|
||||
matches
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue