chore: clippy run

This commit is contained in:
Kevin K 2017-03-09 22:32:32 -05:00
parent 075036c28d
commit 9d4535e1c3
No known key found for this signature in database
GPG key ID: 17218E4B3692F01A
8 changed files with 43 additions and 45 deletions

View file

@ -22,9 +22,9 @@ unicode-width = "0.1.4"
unicode-segmentation = "1.0.1" unicode-segmentation = "1.0.1"
strsim = { version = "0.6.0", optional = true } strsim = { version = "0.6.0", optional = true }
ansi_term = { version = "0.9.0", optional = true } ansi_term = { version = "0.9.0", optional = true }
term_size = { version = "0.2.2", optional = true } term_size = { version = "0.2.3", optional = true }
yaml-rust = { version = "0.3.5", optional = true } yaml-rust = { version = "0.3.5", optional = true }
clippy = { version = "~0.0.112", optional = true } clippy = { version = "~0.0.118", optional = true }
atty = { version = "0.2.2", optional = true } atty = { version = "0.2.2", optional = true }
[dev-dependencies] [dev-dependencies]

View file

@ -217,10 +217,10 @@ impl<'a, 'b> Parser<'a, 'b>
} }
// actually adds the arguments but from a borrow (which means we have to do some clonine) // actually adds the arguments but from a borrow (which means we have to do some clonine)
pub fn add_arg_ref(&mut self, a: &Arg<'a, 'b>) { pub fn add_arg_ref(&mut self, a: &Arg<'a, 'b>) {
self.debug_asserts(&a); self.debug_asserts(a);
self.add_conditional_reqs(&a); self.add_conditional_reqs(a);
self.add_arg_groups(&a); self.add_arg_groups(a);
self.add_reqs(&a); self.add_reqs(a);
if a.index.is_some() || (a.s.short.is_none() && a.s.long.is_none()) { if a.index.is_some() || (a.s.short.is_none() && a.s.long.is_none()) {
let i = if a.index.is_none() { let i = if a.index.is_none() {
(self.positionals.len() + 1) (self.positionals.len() + 1)
@ -779,7 +779,7 @@ impl<'a, 'b> Parser<'a, 'b>
return (true, Some(v[0])); return (true, Some(v[0]));
} }
} }
return (false, None); (false, None)
} }
fn parse_help_subcommand<I, T>(&self, it: &mut I) -> ClapResult<()> fn parse_help_subcommand<I, T>(&self, it: &mut I) -> ClapResult<()>
@ -1324,7 +1324,7 @@ impl<'a, 'b> Parser<'a, 'b>
.expect(INTERNAL_ERROR_MSG) .expect(INTERNAL_ERROR_MSG)
.args { .args {
if self.groups.iter().any(|g| &g.name == &*n) { if self.groups.iter().any(|g| &g.name == &*n) {
args.extend(self.arg_names_in_group(&*n)); args.extend(self.arg_names_in_group(n));
g_vec.push(*n); g_vec.push(*n);
} else { } else {
args.push(*n); args.push(*n);
@ -1504,6 +1504,7 @@ impl<'a, 'b> Parser<'a, 'b>
self.did_you_mean_error(arg.to_str().expect(INVALID_UTF8), matcher).map(|_| None) self.did_you_mean_error(arg.to_str().expect(INVALID_UTF8), matcher).map(|_| None)
} }
#[cfg_attr(feature = "lints", allow(len_zero))]
fn parse_short_arg(&mut self, fn parse_short_arg(&mut self,
matcher: &mut ArgMatcher<'a>, matcher: &mut ArgMatcher<'a>,
full_arg: &OsStr) full_arg: &OsStr)
@ -1882,7 +1883,7 @@ impl<'a, 'b> Parser<'a, 'b>
} }
// Only used for completion scripts due to bin_name messiness // Only used for completion scripts due to bin_name messiness
#[cfg_attr(feature = "lints", allow(explicit_iter_loop))] #[cfg_attr(feature = "lints", allow(block_in_if_condition_stmt))]
pub fn find_subcommand(&'b self, sc: &str) -> Option<&'b App<'a, 'b>> { pub fn find_subcommand(&'b self, sc: &str) -> Option<&'b App<'a, 'b>> {
debugln!("Parser::find_subcommand: sc={}", sc); debugln!("Parser::find_subcommand: sc={}", sc);
debugln!("Parser::find_subcommand: Currently in Parser...{}", debugln!("Parser::find_subcommand: Currently in Parser...{}",

View file

@ -1,4 +1,4 @@
use args::{AnyArg, ArgMatcher}; use args::{AnyArg, ArgMatcher, PosBuilder};
use args::settings::ArgSettings; use args::settings::ArgSettings;
use app::settings::AppSettings as AS; use app::settings::AppSettings as AS;
use app::parser::Parser; use app::parser::Parser;
@ -92,11 +92,8 @@ pub fn create_help_usage(p: &Parser, incl_reqs: bool) -> String {
!p.has_visible_subcommands() { !p.has_visible_subcommands() {
usage.push_str(" [--]") usage.push_str(" [--]")
} }
if p.has_positionals() && let not_req_or_hidden= |p: &PosBuilder| !p.is_set(ArgSettings::Required) && !p.is_set(ArgSettings::Hidden);
p.positionals.values().any(|p| { if p.has_positionals() && p.positionals.values().any(not_req_or_hidden) {
!p.is_set(ArgSettings::Required) &&
!p.is_set(ArgSettings::Hidden)
}) {
if let Some(args_tag) = p.get_args_tag() { if let Some(args_tag) = p.get_args_tag() {
usage.push_str(&*args_tag); usage.push_str(&*args_tag);
} else { } else {
@ -116,12 +113,10 @@ pub fn create_help_usage(p: &Parser, incl_reqs: bool) -> String {
usage.push_str(&*name); usage.push_str(&*name);
usage.push_str(" <SUBCOMMAND>"); usage.push_str(" <SUBCOMMAND>");
} }
} else if p.is_set(AS::SubcommandRequired) || p.is_set(AS::SubcommandRequiredElseHelp) {
usage.push_str(" <SUBCOMMAND>");
} else { } else {
if p.is_set(AS::SubcommandRequired) || p.is_set(AS::SubcommandRequiredElseHelp) { usage.push_str(" [SUBCOMMAND]");
usage.push_str(" <SUBCOMMAND>");
} else {
usage.push_str(" [SUBCOMMAND]");
}
} }
} }
usage.shrink_to_fit(); usage.shrink_to_fit();

View file

@ -42,8 +42,8 @@ impl<'a, 'b, 'z> Validator<'a, 'b, 'z> {
if should_err { if should_err {
return Err(Error::empty_value(o, return Err(Error::empty_value(o,
&*usage::create_error_usage(self.0, &*usage::create_error_usage(self.0,
matcher, matcher,
None), None),
self.0.color())); self.0.color()));
} }
} }
@ -81,9 +81,7 @@ impl<'a, 'b, 'z> Validator<'a, 'b, 'z> {
if self.0.is_set(AS::StrictUtf8) && val.to_str().is_none() { if self.0.is_set(AS::StrictUtf8) && val.to_str().is_none() {
debugln!("Validator::validate_values: invalid UTF-8 found in val {:?}", debugln!("Validator::validate_values: invalid UTF-8 found in val {:?}",
val); val);
return Err(Error::invalid_utf8(&*usage::create_error_usage(self.0, return Err(Error::invalid_utf8(&*usage::create_error_usage(self.0, matcher, None),
matcher,
None),
self.0.color())); self.0.color()));
} }
if let Some(p_vals) = arg.possible_vals() { if let Some(p_vals) = arg.possible_vals() {
@ -94,8 +92,8 @@ impl<'a, 'b, 'z> Validator<'a, 'b, 'z> {
p_vals, p_vals,
arg, arg,
&*usage::create_error_usage(self.0, &*usage::create_error_usage(self.0,
matcher, matcher,
None), None),
self.0.color())); self.0.color()));
} }
} }
@ -117,7 +115,7 @@ impl<'a, 'b, 'z> Validator<'a, 'b, 'z> {
} }
if let Some(vtor) = arg.validator_os() { if let Some(vtor) = arg.validator_os() {
debug!("Validator::validate_values: checking validator_os..."); debug!("Validator::validate_values: checking validator_os...");
if let Err(e) = vtor(&val) { if let Err(e) = vtor(val) {
sdebugln!("error"); sdebugln!("error");
return Err(Error::value_validation(Some(arg), return Err(Error::value_validation(Some(arg),
(*e).to_string_lossy().to_string(), (*e).to_string_lossy().to_string(),
@ -236,8 +234,8 @@ impl<'a, 'b, 'z> Validator<'a, 'b, 'z> {
// Not the first time, and we don't allow multiples // Not the first time, and we don't allow multiples
return Err(Error::unexpected_multiple_usage(a, return Err(Error::unexpected_multiple_usage(a,
&*usage::create_error_usage(self.0, &*usage::create_error_usage(self.0,
matcher, matcher,
None), None),
self.0.color())); self.0.color()));
} }
Ok(()) Ok(())
@ -276,8 +274,8 @@ impl<'a, 'b, 'z> Validator<'a, 'b, 'z> {
"ere" "ere"
}, },
&*usage::create_error_usage(self.0, &*usage::create_error_usage(self.0,
matcher, matcher,
None), None),
self.0.color())); self.0.color()));
} }
} }
@ -292,7 +290,9 @@ impl<'a, 'b, 'z> Validator<'a, 'b, 'z> {
.to_str() .to_str()
.expect(INVALID_UTF8), .expect(INVALID_UTF8),
a, a,
&*usage::create_error_usage(self.0, matcher, None), &*usage::create_error_usage(self.0,
matcher,
None),
self.0.color())); self.0.color()));
} }
} }
@ -303,7 +303,9 @@ impl<'a, 'b, 'z> Validator<'a, 'b, 'z> {
return Err(Error::too_few_values(a, return Err(Error::too_few_values(a,
num, num,
ma.vals.len(), ma.vals.len(),
&*usage::create_error_usage(self.0, matcher, None), &*usage::create_error_usage(self.0,
matcher,
None),
self.0.color())); self.0.color()));
} }
} }
@ -326,10 +328,9 @@ impl<'a, 'b, 'z> Validator<'a, 'b, 'z> {
debugln!("Validator::validate_arg_requires;"); debugln!("Validator::validate_arg_requires;");
if let Some(a_reqs) = a.requires() { if let Some(a_reqs) = a.requires() {
for &(val, name) in a_reqs.iter().filter(|&&(val, _)| val.is_some()) { for &(val, name) in a_reqs.iter().filter(|&&(val, _)| val.is_some()) {
if ma.vals.iter().any(|v| { let missing_req =
v == val.expect(INTERNAL_ERROR_MSG) && |v| v == val.expect(INTERNAL_ERROR_MSG) && !matcher.contains(name);
!matcher.contains(name) if ma.vals.iter().any(missing_req) {
}) {
return self.missing_required_error(matcher, None); return self.missing_required_error(matcher, None);
} }
} }
@ -364,10 +365,8 @@ impl<'a, 'b, 'z> Validator<'a, 'b, 'z> {
// Validate the conditionally required args // Validate the conditionally required args
for &(a, v, r) in &self.0.r_ifs { for &(a, v, r) in &self.0.r_ifs {
if let Some(ma) = matcher.get(a) { if let Some(ma) = matcher.get(a) {
if matcher.get(r).is_none() { if matcher.get(r).is_none() && ma.vals.iter().any(|val| val == v) {
if ma.vals.iter().any(|val| val == v) { return self.missing_required_error(matcher, Some(r));
return self.missing_required_error(matcher, Some(r));
}
} }
} }
} }

View file

@ -110,7 +110,7 @@ impl<'a> ArgMatches<'a> {
/// [`panic!`]: https://doc.rust-lang.org/std/macro.panic!.html /// [`panic!`]: https://doc.rust-lang.org/std/macro.panic!.html
pub fn value_of<S: AsRef<str>>(&self, name: S) -> Option<&str> { pub fn value_of<S: AsRef<str>>(&self, name: S) -> Option<&str> {
if let Some(arg) = self.args.get(name.as_ref()) { if let Some(arg) = self.args.get(name.as_ref()) {
if let Some(v) = arg.vals.iter().nth(0) { if let Some(v) = arg.vals.get(0) {
return Some(v.to_str().expect(INVALID_UTF8)); return Some(v.to_str().expect(INVALID_UTF8));
} }
} }
@ -142,7 +142,7 @@ impl<'a> ArgMatches<'a> {
/// [`Arg::values_of_lossy`]: ./struct.ArgMatches.html#method.values_of_lossy /// [`Arg::values_of_lossy`]: ./struct.ArgMatches.html#method.values_of_lossy
pub fn value_of_lossy<S: AsRef<str>>(&'a self, name: S) -> Option<Cow<'a, str>> { pub fn value_of_lossy<S: AsRef<str>>(&'a self, name: S) -> Option<Cow<'a, str>> {
if let Some(arg) = self.args.get(name.as_ref()) { if let Some(arg) = self.args.get(name.as_ref()) {
if let Some(v) = arg.vals.iter().nth(0) { if let Some(v) = arg.vals.get(0) {
return Some(v.to_string_lossy()); return Some(v.to_string_lossy());
} }
} }
@ -179,7 +179,7 @@ impl<'a> ArgMatches<'a> {
pub fn value_of_os<S: AsRef<str>>(&self, name: S) -> Option<&OsStr> { pub fn value_of_os<S: AsRef<str>>(&self, name: S) -> Option<&OsStr> {
self.args self.args
.get(name.as_ref()) .get(name.as_ref())
.map_or(None, |arg| arg.vals.iter().nth(0).map(|v| v.as_os_str())) .map_or(None, |arg| arg.vals.get(0).map(|v| v.as_os_str()))
} }
/// Gets a [`Values`] struct which implements [`Iterator`] for values of a specific argument /// Gets a [`Values`] struct which implements [`Iterator`] for values of a specific argument

View file

@ -152,6 +152,7 @@ impl<'a> ArgGroup<'a> {
/// assert!(m.is_present("flag")); /// assert!(m.is_present("flag"));
/// ``` /// ```
/// [argument]: ./struct.Arg.html /// [argument]: ./struct.Arg.html
#[cfg_attr(feature = "lints", allow(should_assert_eq))]
pub fn arg(mut self, n: &'a str) -> Self { pub fn arg(mut self, n: &'a str) -> Self {
assert!(self.name != n, assert!(self.name != n,
"ArgGroup '{}' can not have same name as arg inside it", "ArgGroup '{}' can not have same name as arg inside it",

View file

@ -527,6 +527,7 @@
#![cfg_attr(feature = "lints", deny(warnings))] #![cfg_attr(feature = "lints", deny(warnings))]
#![cfg_attr(feature = "lints", allow(cyclomatic_complexity))] #![cfg_attr(feature = "lints", allow(cyclomatic_complexity))]
#![cfg_attr(feature = "lints", allow(doc_markdown))] #![cfg_attr(feature = "lints", allow(doc_markdown))]
#![cfg_attr(feature = "lints", allow(explicit_iter_loop))]
#[cfg(feature = "suggestions")] #[cfg(feature = "suggestions")]
extern crate strsim; extern crate strsim;

View file

@ -68,6 +68,7 @@ pub fn did_you_mean_suffix<'z, T, I>(arg: &str,
} }
/// A helper to determine message formatting /// A helper to determine message formatting
#[derive(Copy, Clone, Debug)]
pub enum DidYouMeanMessageStyle { pub enum DidYouMeanMessageStyle {
/// Suggested value is a long flag /// Suggested value is a long flag
LongFlag, LongFlag,