Skip to content

Don't wrap usage lines in the middle of hyphenated option names - #3814

Open
MaxxxDong wants to merge 1 commit into
pallets:mainfrom
MaxxxDong:fix/usage-wrap-hyphen
Open

Don't wrap usage lines in the middle of hyphenated option names#3814
MaxxxDong wants to merge 1 commit into
pallets:mainfrom
MaxxxDong:fix/usage-wrap-hyphen

Conversation

@MaxxxDong

Copy link
Copy Markdown

Summary

HelpFormatter.write_usage wraps usage arguments with textwrap.TextWrapper, which defaults to break_on_hyphens=True. Hyphenated option names such as --max-retry-count were therefore split across lines:

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

write_usage now passes break_on_hyphens=False so wrapping only happens at spaces. Help-text wrapping is unchanged.

Fixes #3362.

Test plan

  • New regression test using the example from HelpFormatter.write_usage breaks options at a hyphen #3362 (width=65) asserts every option name is intact and no usage line ends with a hyphen.
  • Existing tests/test_formatting.py (38 tests) pass.
  • Full suite minus environment-specific pager tests: 1931 passed.
  • ruff check / ruff format on the touched files.

write_usage used textwrap's default break_on_hyphens, so names like
--max-retry-count were split across lines. Disable that for usage wrapping.
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