Skip to content

Do not break hyphenated tokens when wrapping help text - #3812

Open
syedzeeshan-27 wants to merge 1 commit into
pallets:mainfrom
syedzeeshan-27:wrap-text-no-break-on-hyphens
Open

Do not break hyphenated tokens when wrapping help text#3812
syedzeeshan-27 wants to merge 1 commit into
pallets:mainfrom
syedzeeshan-27:wrap-text-no-break-on-hyphens

Conversation

@syedzeeshan-27

@syedzeeshan-27 syedzeeshan-27 commented Aug 29, 2026

Copy link
Copy Markdown

wrap_text builds click's TextWrapper without overriding textwrap.TextWrapper's default break_on_hyphens=True, so when a usage line or help paragraph has to wrap, an option name can be split at a hyphen:

Usage: program --enable-verbose-logging --output-file-path --max-
               retry-count --disable-cache-mode

This change disables break_on_hyphens so text wraps only at whitespace, keeping names like --max-retry-count intact. This also applies to help paragraphs (write_text), where prose mentioning an option (e.g. "use --enable-verbose-logging instead") had the same problem; the trade-off is that ordinary hyphenated English words are also no longer split, which is the conventional choice for terminal help output. Long tokens that cannot fit on a line by themselves are still hard-broken as a last resort, unchanged.

Added two regression tests (both fail without the fix), a changelog entry, and a versionchanged note on wrap_text.

fixes #3362

`wrap_text` left `textwrap.TextWrapper`'s default
`break_on_hyphens=True` in place, so a usage line or help paragraph
that had to wrap could split an option name at a hyphen, e.g.
`--max-retry-count` became `--max-` / `retry-count`. Wrap only at
whitespace instead.

fixes pallets#3362
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HelpFormatter.write_usage breaks options at a hyphen

1 participant