From 99cdebc23da3a45a165f14b27bebeb2ed828a2ce Mon Sep 17 00:00:00 2001 From: Kevin K Date: Tue, 8 Dec 2015 04:48:23 -0500 Subject: [PATCH] imp: clippy improvements --- src/app/mod.rs | 19 +++++++++---------- src/args/any_arg.rs | 2 ++ src/args/arg_builder/flag.rs | 3 +++ src/args/arg_builder/option.rs | 8 ++++++++ src/args/arg_builder/positional.rs | 4 ++++ 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/app/mod.rs b/src/app/mod.rs index 8deca3cf..8e945999 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -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(&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; } } diff --git a/src/args/any_arg.rs b/src/args/any_arg.rs index 85fffd43..e5211f06 100644 --- a/src/args/any_arg.rs +++ b/src/args/any_arg.rs @@ -16,4 +16,6 @@ pub trait AnyArg<'n> { fn num_vals(&self) -> Option; fn possible_vals(&self) -> Option<&[&'n str]>; fn validator(&self) -> Option<&Rc Result<(), String>>>; + fn short(&self) -> Option; + fn long(&self) -> Option<&'n str>; } diff --git a/src/args/arg_builder/flag.rs b/src/args/arg_builder/flag.rs index a3915177..9ef3e006 100644 --- a/src/args/arg_builder/flag.rs +++ b/src/args/arg_builder/flag.rs @@ -186,6 +186,9 @@ impl<'n> AnyArg<'n> for FlagBuilder<'n> { fn validator(&self) -> Option<&Rc StdResult<(), String>>> { None } fn min_vals(&self) -> Option { None } + fn short(&self) -> Option { self.short } + + fn long(&self) -> Option<&'n str> { self.long } } #[cfg(test)] diff --git a/src/args/arg_builder/option.rs b/src/args/arg_builder/option.rs index ce6b5e9a..57500c23 100644 --- a/src/args/arg_builder/option.rs +++ b/src/args/arg_builder/option.rs @@ -293,6 +293,14 @@ impl<'n> AnyArg<'n> for OptBuilder<'n> { fn min_vals(&self) -> Option { self.min_vals } + + fn short(&self) -> Option { + self.short + } + + fn long(&self) -> Option<&'n str> { + self.long + } } #[cfg(test)] diff --git a/src/args/arg_builder/positional.rs b/src/args/arg_builder/positional.rs index 15702e91..24c9bef3 100644 --- a/src/args/arg_builder/positional.rs +++ b/src/args/arg_builder/positional.rs @@ -214,6 +214,10 @@ impl<'n> AnyArg<'n> for PosBuilder<'n> { fn min_vals(&self) -> Option { self.min_vals } + + fn short(&self) -> Option { None } + + fn long(&self) -> Option<&'n str> { None } } #[cfg(test)]