This commit is contained in:
Kevin K 2015-02-26 20:21:30 -05:00
parent bdc0e22fce
commit 5a2cbb46c1
5 changed files with 34 additions and 7 deletions

2
Cargo.lock generated
View file

@ -1,4 +1,4 @@
[root]
name = "clap"
version = "0.0.3"
version = "0.0.4"

View file

@ -95,6 +95,8 @@ impl App {
short: a.short,
long: a.long,
help: a.help,
multiple: a.multiple,
occurrences: 1
});
}
self
@ -108,9 +110,9 @@ impl App {
fn print_version(&self) {
let ver = match self.version {
Some(v) => v,
None => "0.0"
None => ""
};
println!("{} v{}", self.name, ver);
println!("{} {}", self.name, ver);
unsafe { libc::exit(0); }
}
@ -127,8 +129,16 @@ impl App {
for f in self.flags.iter() {
if let Some(l) = f.long {
if l == p_arg {
found = true;
matches.flags.push(f.clone());
for ff in matches.flags.iter_mut() {
if ff.name == f.name {
// already in matches
ff.occurrences = if ff.multiple { ff.occurrences + 1 } else { 1 };
found = true;
}
}
if ! found {
matches.flags.push(f.clone())
}
return "";
}
}

View file

@ -5,8 +5,8 @@ pub struct Arg {
pub help: Option<&'static str>,
pub required: bool,
pub takes_value: bool,
pub index: Option<u8>
// allow_multiple: bool
pub index: Option<u8>,
pub multiple: bool,
// exclusive_with
// requires
}
@ -20,6 +20,7 @@ impl Arg {
help: None,
required: false,
takes_value: false,
multiple: false,
index: None
}
}
@ -56,4 +57,11 @@ impl Arg {
self.index = Some(idx);
self
}
pub fn multiple(&mut self, multi: bool) -> &mut Arg {
assert!(self.takes_value == false);
assert!(self.index == None);
self.multiple = true;
self
}
}

View file

@ -43,4 +43,11 @@ impl ArgMatches {
}
false
}
pub fn occurrences_of(&self, name: &'static str) -> u8 {
for f in self.flags.iter() {
if f.name == name { return f.occurrences; }
}
0
}
}

View file

@ -4,4 +4,6 @@ pub struct FlagArg {
pub short: Option<char>,
pub long: Option<&'static str>,
pub help: Option<&'static str>,
pub multiple: bool,
pub occurrences: u8
}