Skip to content

Commit 2b144cf

Browse files
authored
Merge pull request #985 from little-dude/clippy
Some clippy fixes
2 parents a6c6e81 + 9d5482e commit 2b144cf

File tree

14 files changed

+168
-196
lines changed

14 files changed

+168
-196
lines changed

src/app/help.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub struct Help<'a> {
8383
// Public Functions
8484
impl<'a> Help<'a> {
8585
/// Create a new `Help` instance.
86+
#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
8687
pub fn new(w: &'a mut Write,
8788
next_line_help: bool,
8889
hide_pv: bool,
@@ -164,9 +165,9 @@ impl<'a> Help<'a> {
164165
if let Some(h) = parser.meta.help_str {
165166
try!(write!(self.writer, "{}", h).map_err(Error::from));
166167
} else if let Some(tmpl) = parser.meta.template {
167-
try!(self.write_templated_help(&parser, tmpl));
168+
try!(self.write_templated_help(parser, tmpl));
168169
} else {
169-
try!(self.write_default_help(&parser));
170+
try!(self.write_default_help(parser));
170171
}
171172
Ok(())
172173
}
@@ -407,9 +408,9 @@ impl<'a> Help<'a> {
407408
fn help<'b, 'c>(&mut self, arg: &ArgWithDisplay<'b, 'c>, spec_vals: &str) -> io::Result<()> {
408409
debugln!("Help::help;");
409410
let h = if self.use_long {
410-
arg.long_help().unwrap_or(arg.help().unwrap_or(""))
411+
arg.long_help().unwrap_or_else(|| arg.help().unwrap_or(""))
411412
} else {
412-
arg.help().unwrap_or(arg.long_help().unwrap_or(""))
413+
arg.help().unwrap_or_else(|| arg.long_help().unwrap_or(""))
413414
};
414415
let mut help = String::from(h) + spec_vals;
415416
let nlh = self.next_line_help || arg.is_set(ArgSettings::NextLineHelp) || self.use_long;
@@ -511,6 +512,7 @@ impl<'a> Help<'a> {
511512
/// Writes help for all arguments (options, flags, args, subcommands)
512513
/// including titles of a Parser Object to the wrapped stream.
513514
#[cfg_attr(feature = "lints", allow(useless_let_if_seq))]
515+
#[cfg_attr(feature = "cargo-clippy", allow(useless_let_if_seq))]
514516
pub fn write_all_args(&mut self, parser: &Parser) -> ClapResult<()> {
515517
debugln!("Help::write_all_args;");
516518
let flags = parser.has_flags();
@@ -563,7 +565,7 @@ impl<'a> Help<'a> {
563565
try!(self.writer.write_all(b"\n\n"));
564566
}
565567
try!(color!(self, "SUBCOMMANDS:\n", warning));
566-
try!(self.write_subcommands(&parser));
568+
try!(self.write_subcommands(parser));
567569
}
568570

569571
Ok(())
@@ -604,7 +606,7 @@ impl<'a> Help<'a> {
604606
/// Writes version of a Parser Object to the wrapped stream.
605607
fn write_version(&mut self, parser: &Parser) -> io::Result<()> {
606608
debugln!("Help::write_version;");
607-
try!(write!(self.writer, "{}", parser.meta.version.unwrap_or("".into())));
609+
try!(write!(self.writer, "{}", parser.meta.version.unwrap_or("")));
608610
Ok(())
609611
}
610612

@@ -648,9 +650,9 @@ impl<'a> Help<'a> {
648650
}};
649651
}
650652
// Print the version
651-
try!(self.write_bin_name(&parser));
653+
try!(self.write_bin_name(parser));
652654
try!(self.writer.write_all(b" "));
653-
try!(self.write_version(&parser));
655+
try!(self.write_version(parser));
654656
try!(self.writer.write_all(b"\n"));
655657
if let Some(author) = parser.meta.author {
656658
write_thing!(author)
@@ -671,7 +673,7 @@ impl<'a> Help<'a> {
671673
let subcmds = parser.has_subcommands();
672674

673675
if flags || opts || pos || subcmds {
674-
try!(self.write_all_args(&parser));
676+
try!(self.write_all_args(parser));
675677
}
676678

677679
if let Some(h) = parser.meta.more_help {
@@ -726,9 +728,9 @@ fn copy_until<R: Read, W: Write>(r: &mut R, w: &mut W, delimiter_byte: u8) -> Co
726728
/// Copies the contents of a reader into a writer until a {tag} is found,
727729
/// copying the tag content to a buffer and returning its size.
728730
/// In addition to errors, there are three possible outputs:
729-
/// - None: The reader was consumed.
730-
/// - Some(Ok(0)): No tag was captured but the reader still contains data.
731-
/// - Some(Ok(length>0)): a tag with `length` was captured to the tag_buffer.
731+
/// - `None`: The reader was consumed.
732+
/// - `Some(Ok(0))`: No tag was captured but the reader still contains data.
733+
/// - `Some(Ok(length>0))`: a tag with `length` was captured to the `tag_buffer`.
732734
fn copy_and_capture<R: Read, W: Write>(r: &mut R,
733735
w: &mut W,
734736
tag_buffer: &mut Cursor<Vec<u8>>)
@@ -842,7 +844,7 @@ impl<'a> Help<'a> {
842844
try!(self.writer.write_all(b"Could not decode tag name"));
843845
}
844846
b"bin" => {
845-
try!(self.write_bin_name(&parser));
847+
try!(self.write_bin_name(parser));
846848
}
847849
b"version" => {
848850
try!(write!(self.writer,
@@ -863,7 +865,7 @@ impl<'a> Help<'a> {
863865
try!(write!(self.writer, "{}", usage::create_usage_no_title(parser, &[])));
864866
}
865867
b"all-args" => {
866-
try!(self.write_all_args(&parser));
868+
try!(self.write_all_args(parser));
867869
}
868870
b"unified" => {
869871
let opts_flags = parser
@@ -882,7 +884,7 @@ impl<'a> Help<'a> {
882884
try!(self.write_args(parser.positionals().map(as_arg_trait)));
883885
}
884886
b"subcommands" => {
885-
try!(self.write_subcommands(&parser));
887+
try!(self.write_subcommands(parser));
886888
}
887889
b"after-help" => {
888890
try!(write!(self.writer,

src/app/macros.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ macro_rules! _handle_group_reqs{
9898
($me:ident, $arg:ident) => ({
9999
use args::AnyArg;
100100
debugln!("_handle_group_reqs!;");
101-
for grp in $me.groups.iter() {
101+
for grp in &$me.groups {
102102
let found = if grp.args.contains(&$arg.name()) {
103-
// vec_remove!($me.required, &$arg.name());
104103
if let Some(ref reqs) = grp.requires {
105104
debugln!("_handle_group_reqs!: Adding {:?} to the required list", reqs);
106105
$me.required.extend(reqs);
@@ -121,7 +120,11 @@ macro_rules! _handle_group_reqs{
121120
debugln!("_handle_group_reqs!:iter: Adding args from group to blacklist...{:?}", grp.args);
122121
if !grp.multiple {
123122
$me.blacklist.extend(&grp.args);
124-
vec_remove!($me.blacklist, &$arg.name());
123+
debugln!("_handle_group_reqs!: removing {:?} from blacklist", $arg.name());
124+
for i in (0 .. $me.blacklist.len()).rev() {
125+
let should_remove = $me.blacklist[i] == $arg.name();
126+
if should_remove { $me.blacklist.swap_remove(i); }
127+
}
125128
}
126129
}
127130
}

0 commit comments

Comments
 (0)