mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
imp: clippy improvements
This commit is contained in:
parent
6b54ba2e45
commit
99cdebc23d
5 changed files with 26 additions and 10 deletions
|
@ -1637,7 +1637,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar> {
|
|||
}
|
||||
|
||||
// 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,
|
||||
matcher: &mut ArgMatcher<'ar>,
|
||||
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));
|
||||
|
||||
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(" ");
|
||||
|
@ -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)
|
||||
assert!(!self.positionals
|
||||
.values()
|
||||
.any(|a| {
|
||||
.any(|a|
|
||||
a.settings.is_set(&ArgSettings::Multiple) &&
|
||||
(a.index as usize != self.positionals.len())
|
||||
}),
|
||||
),
|
||||
"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
|
||||
|
@ -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,
|
||||
matcher: &mut ArgMatcher<'ar>,
|
||||
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)
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "lints", allow(cyclomatic_complexity))]
|
||||
fn parse_short_arg(&mut self,
|
||||
matcher: &mut ArgMatcher<'ar>,
|
||||
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);
|
||||
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
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() {
|
||||
} else 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
|
||||
try!(self.check_for_help_and_version_char(c));
|
||||
try!(self.parse_flag(flag, matcher));
|
||||
// Handle conflicts, requirements, overrides, etc.
|
||||
// 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;
|
||||
} else if self.groups
|
||||
.get(n)
|
||||
.map(|g| g.args.iter().any(|an| matcher.contains(an)))
|
||||
.unwrap_or(false) {
|
||||
.map_or(false, |g| g.args.iter().any(|an| matcher.contains(an))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,4 +16,6 @@ pub trait AnyArg<'n> {
|
|||
fn num_vals(&self) -> Option<u8>;
|
||||
fn possible_vals(&self) -> Option<&[&'n str]>;
|
||||
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 min_vals(&self) -> Option<u8> { None }
|
||||
fn short(&self) -> Option<char> { self.short }
|
||||
|
||||
fn long(&self) -> Option<&'n str> { self.long }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -293,6 +293,14 @@ impl<'n> AnyArg<'n> for OptBuilder<'n> {
|
|||
fn min_vals(&self) -> Option<u8> {
|
||||
self.min_vals
|
||||
}
|
||||
|
||||
fn short(&self) -> Option<char> {
|
||||
self.short
|
||||
}
|
||||
|
||||
fn long(&self) -> Option<&'n str> {
|
||||
self.long
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -214,6 +214,10 @@ impl<'n> AnyArg<'n> for PosBuilder<'n> {
|
|||
fn min_vals(&self) -> Option<u8> {
|
||||
self.min_vals
|
||||
}
|
||||
|
||||
fn short(&self) -> Option<char> { None }
|
||||
|
||||
fn long(&self) -> Option<&'n str> { None }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Reference in a new issue