mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 23:02:31 +00:00
commit
82f984504a
6 changed files with 28 additions and 12 deletions
|
@ -12,12 +12,12 @@ license = "MIT"
|
||||||
keywords = ["argument", "command", "arg", "parser", "parse"]
|
keywords = ["argument", "command", "arg", "parser", "parse"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "0.3.2"
|
bitflags = "0.3.3"
|
||||||
vec_map = "0.4"
|
vec_map = "0.4"
|
||||||
ansi_term = { version = "~0.7", optional = true }
|
ansi_term = { version = "~0.7", optional = true }
|
||||||
strsim = { version = "~0.4.0", optional = true }
|
strsim = { version = "~0.4.0", optional = true }
|
||||||
yaml-rust = { version = "~0.2.2", optional = true }
|
yaml-rust = { version = "~0.2.2", optional = true }
|
||||||
clippy = { version = "~0.0.22", optional = true }
|
clippy = { version = "~0.0.29", optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["suggestions", "color"]
|
default = ["suggestions", "color"]
|
||||||
|
|
|
@ -1637,7 +1637,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// The actual parsing function
|
// The actual parsing function
|
||||||
#[cfg_attr(feature="lints", allow(while_let_on_iterator))]
|
#[cfg_attr(feature="lints", allow(while_let_on_iterator, cyclomatic_complexity))]
|
||||||
fn get_matches_with<I, T>(&mut self,
|
fn get_matches_with<I, T>(&mut self,
|
||||||
matcher: &mut ArgMatcher<'ar>,
|
matcher: &mut ArgMatcher<'ar>,
|
||||||
it: &mut I,
|
it: &mut I,
|
||||||
|
@ -1801,7 +1801,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar> {
|
||||||
let reqs = self.get_required_from(&hs, Some(matcher));
|
let reqs = self.get_required_from(&hs, Some(matcher));
|
||||||
|
|
||||||
for s in reqs.iter() {
|
for s in reqs.iter() {
|
||||||
write!(&mut mid_string, " {}", s).ok().expect(INTERNAL_ERROR_MSG);
|
write!(&mut mid_string, " {}", s).expect(INTERNAL_ERROR_MSG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mid_string.push_str(" ");
|
mid_string.push_str(" ");
|
||||||
|
@ -2154,10 +2154,10 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar> {
|
||||||
// Next we verify that only the highest index has a .multiple(true) (if any)
|
// Next we verify that only the highest index has a .multiple(true) (if any)
|
||||||
assert!(!self.positionals
|
assert!(!self.positionals
|
||||||
.values()
|
.values()
|
||||||
.any(|a| {
|
.any(|a|
|
||||||
a.settings.is_set(&ArgSettings::Multiple) &&
|
a.settings.is_set(&ArgSettings::Multiple) &&
|
||||||
(a.index as usize != self.positionals.len())
|
(a.index as usize != self.positionals.len())
|
||||||
}),
|
),
|
||||||
"Only the positional argument with the highest index may accept multiple values");
|
"Only the positional argument with the highest index may accept multiple values");
|
||||||
|
|
||||||
// If it's required we also need to ensure all previous positionals are
|
// If it's required we also need to ensure all previous positionals are
|
||||||
|
@ -2328,6 +2328,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "lints", allow(cyclomatic_complexity))]
|
||||||
fn parse_long_arg<'av>(&mut self,
|
fn parse_long_arg<'av>(&mut self,
|
||||||
matcher: &mut ArgMatcher<'ar>,
|
matcher: &mut ArgMatcher<'ar>,
|
||||||
full_arg: &'av str)
|
full_arg: &'av str)
|
||||||
|
@ -2368,6 +2369,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar> {
|
||||||
self.did_you_mean_error(arg, matcher).map(|_| None)
|
self.did_you_mean_error(arg, matcher).map(|_| None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "lints", allow(cyclomatic_complexity))]
|
||||||
fn parse_short_arg(&mut self,
|
fn parse_short_arg(&mut self,
|
||||||
matcher: &mut ArgMatcher<'ar>,
|
matcher: &mut ArgMatcher<'ar>,
|
||||||
full_arg: &str)
|
full_arg: &str)
|
||||||
|
@ -2391,11 +2393,9 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar> {
|
||||||
arg_post_processing!(self, opt, matcher);
|
arg_post_processing!(self, opt, matcher);
|
||||||
|
|
||||||
return Ok(ret);
|
return Ok(ret);
|
||||||
}
|
} else if let Some(flag) = self.flags.iter().filter(|&v| v.short.is_some() && v.short.unwrap() == c).next() {
|
||||||
|
|
||||||
try!(self.check_for_help_and_version_char(c));
|
|
||||||
if let Some(flag) = self.flags.iter().filter(|&v| v.short.is_some() && v.short.unwrap() == c).next() {
|
|
||||||
// Only flags can be help or version
|
// Only flags can be help or version
|
||||||
|
try!(self.check_for_help_and_version_char(c));
|
||||||
try!(self.parse_flag(flag, matcher));
|
try!(self.parse_flag(flag, matcher));
|
||||||
// Handle conflicts, requirements, overrides, etc.
|
// Handle conflicts, requirements, overrides, etc.
|
||||||
// Must be called here due to mutablilty
|
// Must be called here due to mutablilty
|
||||||
|
@ -2745,8 +2745,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar> {
|
||||||
return true;
|
return true;
|
||||||
} else if self.groups
|
} else if self.groups
|
||||||
.get(n)
|
.get(n)
|
||||||
.map(|g| g.args.iter().any(|an| matcher.contains(an)))
|
.map_or(false, |g| g.args.iter().any(|an| matcher.contains(an))) {
|
||||||
.unwrap_or(false) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,4 +16,6 @@ pub trait AnyArg<'n> {
|
||||||
fn num_vals(&self) -> Option<u8>;
|
fn num_vals(&self) -> Option<u8>;
|
||||||
fn possible_vals(&self) -> Option<&[&'n str]>;
|
fn possible_vals(&self) -> Option<&[&'n str]>;
|
||||||
fn validator(&self) -> Option<&Rc<Fn(String) -> Result<(), String>>>;
|
fn validator(&self) -> Option<&Rc<Fn(String) -> Result<(), String>>>;
|
||||||
|
fn short(&self) -> Option<char>;
|
||||||
|
fn long(&self) -> Option<&'n str>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,6 +186,9 @@ impl<'n> AnyArg<'n> for FlagBuilder<'n> {
|
||||||
fn validator(&self) -> Option<&Rc<Fn(String) -> StdResult<(), String>>> { None }
|
fn validator(&self) -> Option<&Rc<Fn(String) -> StdResult<(), String>>> { None }
|
||||||
|
|
||||||
fn min_vals(&self) -> Option<u8> { None }
|
fn min_vals(&self) -> Option<u8> { None }
|
||||||
|
fn short(&self) -> Option<char> { self.short }
|
||||||
|
|
||||||
|
fn long(&self) -> Option<&'n str> { self.long }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -293,6 +293,14 @@ impl<'n> AnyArg<'n> for OptBuilder<'n> {
|
||||||
fn min_vals(&self) -> Option<u8> {
|
fn min_vals(&self) -> Option<u8> {
|
||||||
self.min_vals
|
self.min_vals
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn short(&self) -> Option<char> {
|
||||||
|
self.short
|
||||||
|
}
|
||||||
|
|
||||||
|
fn long(&self) -> Option<&'n str> {
|
||||||
|
self.long
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -214,6 +214,10 @@ impl<'n> AnyArg<'n> for PosBuilder<'n> {
|
||||||
fn min_vals(&self) -> Option<u8> {
|
fn min_vals(&self) -> Option<u8> {
|
||||||
self.min_vals
|
self.min_vals
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn short(&self) -> Option<char> { None }
|
||||||
|
|
||||||
|
fn long(&self) -> Option<&'n str> { None }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in a new issue