Don't break hyphenated options across lines in the usage line#3437
Closed
c-tonneslan wants to merge 1 commit into
Closed
Don't break hyphenated options across lines in the usage line#3437c-tonneslan wants to merge 1 commit into
c-tonneslan wants to merge 1 commit into
Conversation
textwrap.TextWrapper defaults to break_on_hyphens=True, so when HelpFormatter.write_usage wraps an args string like "--enable-verbose-logging --output-file-path ..." at a narrow width, options end up split mid-word as "--max-" / "retry-count" on adjacent lines. That's confusing in help output. Add a break_on_hyphens parameter to wrap_text that forwards to the underlying TextWrapper, defaulting to True so existing behavior is preserved everywhere else. write_usage passes False to keep option names atomic. Closes pallets#3362. Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3362.
textwrap.TextWrapperdefaults tobreak_on_hyphens=True, so whenHelpFormatter.write_usagewraps a long args string at a narrow width, option names get split mid-word:Adds a
break_on_hyphensparameter towrap_textthat forwards toTextWrapper. The default staysTrueso existing callers (write_text,write_dl, paragraph wrapping) keep their current behavior.write_usagepassesFalseso each option name stays on a single line:Verified against the reproducer from the issue (output matches the expected block exactly).
Added two regression tests in
test_formatting.py:test_write_usage_does_not_break_options_at_hyphenchecks the issue's specific scenario viaHelpFormatter.write_usagetest_wrap_text_break_on_hyphens_opt_inexercises the new parameter directly and confirms the default still splits at hyphens