aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-01-09 23:18:41 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2014-01-09 23:18:41 +0200
commit123e6d5b4b17e182cfa49b0913bfc0b77ecb2585 (patch)
treeb172af053a1970f2530d1771f81b97b1430d4d5d /Lib/argparse.py
parentTry to fix test_ssl failures on some buildbots (diff)
parentIssue #13107: argparse and optparse no longer raises an exception when output (diff)
downloadcpython-123e6d5b4b17e182cfa49b0913bfc0b77ecb2585.tar.gz
cpython-123e6d5b4b17e182cfa49b0913bfc0b77ecb2585.tar.bz2
cpython-123e6d5b4b17e182cfa49b0913bfc0b77ecb2585.zip
Issue #13107: argparse and optparse no longer raises an exception when output
a help on environment with too small COLUMNS. Based on patch by Elazar Gershuni.
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r--Lib/argparse.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index 9520e0ea7c6..5ad7e13a480 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -165,6 +165,8 @@ class HelpFormatter(object):
self._prog = prog
self._indent_increment = indent_increment
self._max_help_position = max_help_position
+ self._max_help_position = min(max_help_position,
+ max(width - 20, indent_increment * 2))
self._width = width
self._current_indent = 0
@@ -336,7 +338,7 @@ class HelpFormatter(object):
else:
line_len = len(indent) - 1
for part in parts:
- if line_len + 1 + len(part) > text_width:
+ if line_len + 1 + len(part) > text_width and line:
lines.append(indent + ' '.join(line))
line = []
line_len = len(indent) - 1
@@ -476,7 +478,7 @@ class HelpFormatter(object):
def _format_text(self, text):
if '%(prog)' in text:
text = text % dict(prog=self._prog)
- text_width = self._width - self._current_indent
+ text_width = max(self._width - self._current_indent, 11)
indent = ' ' * self._current_indent
return self._fill_text(text, text_width, indent) + '\n\n'
@@ -484,7 +486,7 @@ class HelpFormatter(object):
# determine the required width and the entry label
help_position = min(self._action_max_length + 2,
self._max_help_position)
- help_width = self._width - help_position
+ help_width = max(self._width - help_position, 11)
action_width = help_position - self._current_indent - 2
action_header = self._format_action_invocation(action)