mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
v0.3.1
This commit is contained in:
parent
e753b020e6
commit
8a62206639
4 changed files with 54 additions and 8 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1,4 +1,4 @@
|
|||
[root]
|
||||
name = "clap"
|
||||
version = "0.0.5"
|
||||
version = "0.3.0"
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
|
||||
name = "clap"
|
||||
version = "0.0.5"
|
||||
version = "0.3.0"
|
||||
authors = ["Kevin K. <kbknapp@gmail.com>"]
|
||||
|
|
35
src/app.rs
35
src/app.rs
|
@ -78,6 +78,7 @@ impl App {
|
|||
index: i,
|
||||
required: a.required,
|
||||
help: a.help,
|
||||
blacklist: a.blacklist.clone(),
|
||||
requires: a.requires.clone(),
|
||||
value: None
|
||||
});
|
||||
|
@ -85,6 +86,7 @@ impl App {
|
|||
name: a.name,
|
||||
index: i,
|
||||
required: a.required,
|
||||
blacklist: a.blacklist.clone(),
|
||||
requires: a.requires.clone(),
|
||||
help: a.help,
|
||||
value: None
|
||||
|
@ -94,6 +96,7 @@ impl App {
|
|||
name: a.name,
|
||||
short: a.short,
|
||||
long: a.long,
|
||||
blacklist: a.blacklist.clone(),
|
||||
help: a.help,
|
||||
requires: a.requires.clone(),
|
||||
required: a.required,
|
||||
|
@ -123,6 +126,7 @@ impl App {
|
|||
short: a.short,
|
||||
long: a.long,
|
||||
help: a.help,
|
||||
blacklist: a.blacklist.clone(),
|
||||
multiple: a.multiple,
|
||||
requires: a.requires.clone(),
|
||||
occurrences: 1
|
||||
|
@ -209,7 +213,16 @@ impl App {
|
|||
self.report_error(&format!("The argument -{} is mutually exclusive with one or more other arguments", arg),
|
||||
false, true);
|
||||
}
|
||||
matches.flags.insert(k, v.clone());
|
||||
matches.flags.insert(k, FlagArg{
|
||||
name: v.name,
|
||||
short: v.short,
|
||||
long: v.long,
|
||||
help: v.help,
|
||||
multiple: v.multiple,
|
||||
occurrences: v.occurrences,
|
||||
blacklist: None,
|
||||
requires: None
|
||||
});
|
||||
if self.required.contains(k) {
|
||||
self.required.remove(k);
|
||||
}
|
||||
|
@ -271,7 +284,8 @@ impl App {
|
|||
long: v.long,
|
||||
help: v.help,
|
||||
required: v.required,
|
||||
requires: v.requires.clone(),
|
||||
blacklist: None,
|
||||
requires: None,
|
||||
value: arg_val.clone()
|
||||
});
|
||||
match arg_val {
|
||||
|
@ -299,7 +313,16 @@ impl App {
|
|||
self.report_error(&format!("The argument --{} is mutually exclusive with one or more other arguments", arg),
|
||||
false, true);
|
||||
}
|
||||
matches.flags.insert(k, v.clone());
|
||||
matches.flags.insert(k, FlagArg{
|
||||
name: v.name,
|
||||
short: v.short,
|
||||
long: v.long,
|
||||
help: v.help,
|
||||
multiple: v.multiple,
|
||||
occurrences: v.occurrences,
|
||||
blacklist: None,
|
||||
requires: None
|
||||
});
|
||||
if self.required.contains(k) {
|
||||
self.required.remove(k);
|
||||
}
|
||||
|
@ -401,7 +424,8 @@ impl App {
|
|||
short: opt.short,
|
||||
long: opt.long,
|
||||
help: opt.help,
|
||||
requires: opt.requires.clone(),
|
||||
requires: None,
|
||||
blacklist: None,
|
||||
required: opt.required,
|
||||
value: Some(arg.clone())
|
||||
});
|
||||
|
@ -455,7 +479,8 @@ impl App {
|
|||
name: p.name,
|
||||
help: p.help,
|
||||
required: p.required,
|
||||
requires: p.requires.clone(),
|
||||
blacklist: None,
|
||||
requires: None,
|
||||
value: Some(arg.clone()),
|
||||
index: pos_counter
|
||||
});
|
||||
|
|
23
src/arg.rs
23
src/arg.rs
|
@ -7,7 +7,7 @@ pub struct Arg {
|
|||
pub takes_value: bool,
|
||||
pub index: Option<u8>,
|
||||
pub multiple: bool,
|
||||
// exclusive_with
|
||||
pub blacklist: Option<Vec<&'static str>>,
|
||||
pub requires: Option<Vec<&'static str>>
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ impl Arg {
|
|||
takes_value: false,
|
||||
multiple: false,
|
||||
index: None,
|
||||
blacklist: Some(vec![]),
|
||||
requires: Some(vec![]),
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +48,26 @@ impl Arg {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn mutually_excludes(&mut self, name: &'static str) -> &mut Arg {
|
||||
if let Some(ref mut vec) = self.blacklist {
|
||||
vec.push(name);
|
||||
} else {
|
||||
self.blacklist = Some(vec![]);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn mutually_excludes_all(&mut self, names: Vec<&'static str>) -> &mut Arg {
|
||||
if let Some(ref mut vec) = self.blacklist {
|
||||
for n in names {
|
||||
vec.push(n);
|
||||
}
|
||||
} else {
|
||||
self.blacklist = Some(vec![]);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn requires(&mut self, name: &'static str) -> &mut Arg {
|
||||
if let Some(ref mut vec) = self.requires {
|
||||
vec.push(name);
|
||||
|
|
Loading…
Reference in a new issue