Skip to content

Commit

Permalink
Merge pull request #3692 from epage/break
Browse files Browse the repository at this point in the history
fix(help): Don't wrap URLs
  • Loading branch information
epage committed May 4, 2022
2 parents fff1b11 + c7ff695 commit 41a8a5b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/output/help.rs
Expand Up @@ -1127,7 +1127,9 @@ fn should_show_subcommand(subcommand: &Command) -> bool {
}

fn text_wrapper(help: &str, width: usize) -> String {
let wrapper = textwrap::Options::new(width).break_words(false);
let wrapper = textwrap::Options::new(width)
.break_words(false)
.word_splitter(textwrap::WordSplitter::NoHyphenation);
help.lines()
.map(|line| textwrap::fill(line, &wrapper))
.collect::<Vec<String>>()
Expand Down
31 changes: 31 additions & 0 deletions tests/builder/help.rs
Expand Up @@ -1221,6 +1221,37 @@ fn wrapping_newline_variables() {
utils::assert_output(cmd, "ctest --help", WRAPPING_NEWLINE_CHARS, false);
}

#[test]
fn dont_wrap_urls() {
let cmd = Command::new("Example")
.term_width(30)
.subcommand(Command::new("update").arg(
Arg::new("force-non-host")
.help("Install toolchains that require an emulator. See https://github.com/rust-lang/rustup/wiki/Non-host-toolchains")
.long("force-non-host")
.takes_value(false))
);

const EXPECTED: &str = "\
Example-update
USAGE:
Example update [OPTIONS]
OPTIONS:
--force-non-host
Install toolchains
that require an
emulator. See
https://github.com/rust-lang/rustup/wiki/Non-host-toolchains
-h, --help
Print help
information
";
utils::assert_output(cmd, "Example update --help", EXPECTED, false);
}

#[test]
fn old_newline_chars() {
let cmd = Command::new("ctest").version("0.1").arg(
Expand Down

0 comments on commit 41a8a5b

Please sign in to comment.