Inject width via pylib to argparse formatter
`argparse.HelpFormatter` looks at `$COLUMNS` only, falling back to a default of 80. `py.io.get_terminal_width()` is smarter there, and could even work better with https://github.com/pytest-dev/py/pull/219. This ensures to use a consistent value for formatting the ini values etc.
This commit is contained in:
@@ -405,6 +405,12 @@ class DropShorterLongHelpFormatter(argparse.HelpFormatter):
|
||||
- cache result on action object as this is called at least 2 times
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Use more accurate terminal width via pylib."""
|
||||
if "width" not in kwargs:
|
||||
kwargs["width"] = py.io.get_terminal_width()
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def _format_action_invocation(self, action):
|
||||
orgstr = argparse.HelpFormatter._format_action_invocation(self, action)
|
||||
if orgstr and orgstr[0] != "-": # only optional arguments
|
||||
|
||||
Reference in New Issue
Block a user