Skip to content

Commit

Permalink
imp: removes extra newline from help output
Browse files Browse the repository at this point in the history
  • Loading branch information
kbknapp committed May 31, 2016
1 parent 65b1de6 commit 86e61d1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
41 changes: 23 additions & 18 deletions src/app/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<'a> Help<'a> {
/// Writes the parser help to the wrapped stream.
pub fn write_help(&mut self, parser: &Parser) -> ClapResult<()> {
if let Some(h) = parser.meta.help_str {
try!(writeln!(self.writer, "{}", h).map_err(Error::from));
try!(write!(self.writer, "{}", h).map_err(Error::from));
} else if let Some(ref tmpl) = parser.meta.template {
try!(self.write_templated_help(&parser, tmpl));
} else {
Expand Down Expand Up @@ -143,7 +143,13 @@ impl<'a> Help<'a> {
arg_v.push(arg)
}
}
let mut first = true;
for arg in arg_v {
if !first {
try!(self.writer.write(b"\n"));
} else {
first = false;
};
try!(self.write_arg(arg.as_base(), longest));
}
Ok(())
Expand All @@ -166,8 +172,14 @@ impl<'a> Help<'a> {
btm.insert(arg.name(), arg);
}
}
let mut first = true;
for (_, btm) in ord_m.into_iter() {
for (_, arg) in btm.into_iter() {
if !first {
try!(self.writer.write(b"\n"));
} else {
first = false;
};
try!(self.write_arg(arg.as_base(), longest));
}
}
Expand All @@ -184,7 +196,6 @@ impl<'a> Help<'a> {
try!(self.long(arg, longest));
try!(self.val(arg, longest));
try!(self.help(arg, longest));
try!(self.writer.write(b"\n"));
Ok(())
}

Expand Down Expand Up @@ -458,45 +469,33 @@ impl<'a> Help<'a> {

let unified_help = parser.is_set(AppSettings::UnifiedHelpMessage);

let mut first = true;

if unified_help && (flags || opts) {
let opts_flags = parser.iter_flags()
.map(as_arg_trait)
.chain(parser.iter_opts().map(as_arg_trait));
try!(color!(self, "OPTIONS:\n", Warning));
try!(self.write_args(opts_flags));
first = false;
} else {
if flags {
try!(color!(self, "FLAGS:\n", Warning));
try!(self.write_args(parser.iter_flags()
.map(as_arg_trait)));
first = false;
}
if opts {
if !first {
try!(self.writer.write(b"\n"));
}
try!(self.writer.write(b"\n\n"));
try!(color!(self, "OPTIONS:\n", Warning));
try!(self.write_args(parser.iter_opts().map(as_arg_trait)));
first = false;
}
}

if pos {
if !first {
try!(self.writer.write(b"\n"));
}
try!(self.writer.write(b"\n\n"));
try!(color!(self, "ARGS:\n", Warning));
try!(self.write_args_unsorted(parser.iter_positionals().map(as_arg_trait)));
first = false;
}

if subcmds {
if !first {
try!(self.writer.write(b"\n"));
}
try!(self.writer.write(b"\n\n"));
try!(color!(self, "SUBCOMMANDS:\n", Warning));
try!(self.write_subcommands(&parser));
}
Expand All @@ -515,8 +514,14 @@ impl<'a> Help<'a> {
longest = cmp::max(longest, sc.p.meta.name.len());
}

let mut first = true;
for (_, btm) in ord_m.into_iter() {
for (_, sc) in btm.into_iter() {
if !first {
try!(self.writer.write(b"\n"));
} else {
first = false;
}
try!(self.write_arg(sc, longest));
}
}
Expand Down Expand Up @@ -575,7 +580,7 @@ impl<'a> Help<'a> {
}

if let Some(h) = parser.meta.more_help {
try!(write!(self.writer, "{}\n", h));
try!(write!(self.writer, "{}", h));
}

self.writer.flush().map_err(Error::from)
Expand Down
1 change: 0 additions & 1 deletion src/app/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,6 @@ impl<'a, 'b> Parser<'a, 'b>
self.write_help(&mut buf_w)
}

#[cfg_attr(feature = "lints", allow(for_kv_map))]
pub fn write_help<W: Write>(&self, w: &mut W) -> ClapResult<()> {
Help::write_parser_help(w, &self)
}
Expand Down

0 comments on commit 86e61d1

Please sign in to comment.