diff --git a/argparse.py b/argparse.py index 2dad5f1..f420079 100644 --- a/argparse.py +++ b/argparse.py @@ -162,12 +162,15 @@ class HelpFormatter(object): prog, indent_increment=2, max_help_position=24, + max_text_width=None width=None): # default setting for width if width is None: width = _shutil.get_terminal_size().columns width -= 2 + if max_text_width: + width = min(max_text_width, width) self._prog = prog self._indent_increment = indent_increment @@ -1626,6 +1629,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): - epilog -- Text following the argument descriptions - parents -- Parsers whose arguments should be copied into this one - formatter_class -- HelpFormatter class for printing help messages + - max_text_width -- Maximum text width when printing help messages - prefix_chars -- Characters that prefix optional arguments - fromfile_prefix_chars -- Characters that prefix files containing additional arguments @@ -1642,6 +1646,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): epilog=None, parents=[], formatter_class=HelpFormatter, + max_text_width=None, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, @@ -1663,6 +1668,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): self.usage = usage self.epilog = epilog self.formatter_class = formatter_class + self.max_text_width = max_text_width self.fromfile_prefix_chars = fromfile_prefix_chars self.add_help = add_help self.allow_abbrev = allow_abbrev @@ -2478,7 +2484,8 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): return formatter.format_help() def _get_formatter(self): - return self.formatter_class(prog=self.prog) + return self.formatter_class(prog=self.prog, + max_text_width=self.max_text_width) # ===================== # Help-printing methods