Skip to content

Commit

Permalink
Do not wrap short help (-h) output
Browse files Browse the repository at this point in the history
  • Loading branch information
th1000s authored and dandavison committed Aug 12, 2024
1 parent 2c8292f commit a01141b
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1227,15 +1227,17 @@ impl Opt {
}
Err(e) if e.kind() == clap::error::ErrorKind::DisplayHelp => {
let term = Term::stdout();
// find out if short or long version of --help was used:
let long_help = !args.iter().any(|arg| arg == "-h");
let help_clap = if long_help {
Self::command().render_long_help()
} else {
Self::command().render_help()
};
// No wrapping if short -h instead of --help was used:
if args.iter().any(|arg| arg == "-h") {
let help_clap = Self::command().render_help();
return Call::Help(if term.is_term() {
help_clap.ansi().to_string()
} else {
help_clap.to_string()
});
}

let is_term = term.is_term();
let help_clap = Self::command().render_long_help();
let (help_clap, wrap_width) = if term.is_term() {
(
help_clap.ansi().to_string(),
Expand All @@ -1250,19 +1252,17 @@ impl Opt {
wrap_width.clamp(TERM_FALLBACK_WIDTH - 22, TERM_FALLBACK_WIDTH + 22) - 2;

let mut help = utils::helpwrap::wrap(&help_clap, wrap_width, "", "", "");
if long_help {
let indent_with = " ";
let no_indent = ":no_Indent:";
let no_wrap = ":no_Wrap:";
let after_help = utils::helpwrap::wrap(
&get_after_long_help(is_term, no_indent, no_wrap),
wrap_width,
indent_with,
no_indent,
no_wrap,
);
help.push_str(&after_help);
}
let indent_with = " ";
let no_indent = ":no_Indent:";
let no_wrap = ":no_Wrap:";
let after_help = utils::helpwrap::wrap(
&get_after_long_help(term.is_term(), no_indent, no_wrap),
wrap_width,
indent_with,
no_indent,
no_wrap,
);
help.push_str(&after_help);

Call::Help(help)
}
Expand Down

0 comments on commit a01141b

Please sign in to comment.