Skip to content

Commit

Permalink
imp: clippy improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
kbknapp committed Dec 8, 2015
1 parent 6b54ba2 commit 99cdebc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(" ");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/args/any_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
}
3 changes: 3 additions & 0 deletions src/args/arg_builder/flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
8 changes: 8 additions & 0 deletions src/args/arg_builder/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 4 additions & 0 deletions src/args/arg_builder/positional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 99cdebc

Please sign in to comment.