mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 23:04:23 +00:00
v0.0.4.4
This commit is contained in:
parent
59d78cc9bd
commit
b2852be529
1 changed files with 34 additions and 32 deletions
56
src/app.rs
56
src/app.rs
|
@ -116,6 +116,31 @@ impl App {
|
|||
unsafe { libc::exit(0); }
|
||||
}
|
||||
|
||||
fn validate_short_flag(&self, matches: &mut ArgMatches, arg: char) -> bool {
|
||||
let mut found = false;
|
||||
for f in self.flags.iter() {
|
||||
if let Some(s) = f.short {
|
||||
if s == arg {
|
||||
found = true;
|
||||
let mut mult = false;
|
||||
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 };
|
||||
mult = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ! mult {
|
||||
matches.flags.push(f.clone())
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
found
|
||||
}
|
||||
|
||||
fn parse_long_arg(&self, matches: &mut ArgMatches, arg: &str) -> &'static str {
|
||||
let mut p_arg = arg.trim_left_matches(|c| c == '-');
|
||||
let mut found = false;
|
||||
|
@ -191,25 +216,7 @@ impl App {
|
|||
} else if c == 'v' && self.needs_short_version {
|
||||
self.print_version();
|
||||
}
|
||||
for f in self.flags.iter() {
|
||||
if let Some(s) = f.short {
|
||||
if s == c {
|
||||
found = true;
|
||||
let mut mult = false;
|
||||
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 };
|
||||
mult = true;
|
||||
}
|
||||
}
|
||||
if ! mult {
|
||||
matches.flags.push(f.clone())
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
found = self.validate_short_flag(matches, c);
|
||||
// Fails if argument supplied to binary isn't valid
|
||||
assert!(found == false);
|
||||
return "";
|
||||
|
@ -222,14 +229,8 @@ impl App {
|
|||
} else if p_arg == 'v' && self.needs_short_version {
|
||||
self.print_version();
|
||||
}
|
||||
for f in self.flags.iter() {
|
||||
if let Some(s) = f.short {
|
||||
if p_arg == s {
|
||||
found = true;
|
||||
matches.flags.push(f.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
found = self.validate_short_flag(matches, p_arg);
|
||||
if ! found {
|
||||
for o in self.opts.iter() {
|
||||
if let Some(s) = o.short {
|
||||
if s == p_arg {
|
||||
|
@ -238,6 +239,7 @@ impl App {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Fails if argument supplied to binary isn't valid
|
||||
assert!(found == false);
|
||||
|
||||
|
|
Loading…
Reference in a new issue