diff options
author | steven.bethard <devnull@localhost> | 2009-07-13 00:02:35 +0000 |
---|---|---|
committer | steven.bethard <devnull@localhost> | 2009-07-13 00:02:35 +0000 |
commit | be051b2738ef9e459651e3c75a24f0ce97374d0c (patch) | |
tree | a9b4516c18bae17149d6059fdfa9150bc4779201 /argparse.py | |
parent | 85f71279479f91b17f2eb9e79c38d576538fa242 (diff) | |
download | argparse-be051b2738ef9e459651e3c75a24f0ce97374d0c.tar.gz |
Add ArgumentDefaultsHelpFormatter.
Diffstat (limited to 'argparse.py')
-rw-r--r-- | argparse.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/argparse.py b/argparse.py index 4ae1c89..8ee556b 100644 --- a/argparse.py +++ b/argparse.py @@ -549,7 +549,7 @@ class HelpFormatter(object): if params.get('choices') is not None:
choices_str = ', '.join([str(c) for c in params['choices']])
params['choices'] = choices_str
- return action.help % params
+ return self._get_help_string(action) % params
def _iter_indented_subactions(self, action):
try:
@@ -571,6 +571,9 @@ class HelpFormatter(object): return _textwrap.fill(text, width, initial_indent=indent,
subsequent_indent=indent)
+ def _get_help_string(self, action):
+ return action.help
+
class RawDescriptionHelpFormatter(HelpFormatter):
@@ -584,6 +587,18 @@ class RawTextHelpFormatter(RawDescriptionHelpFormatter): return text.splitlines()
+class ArgumentDefaultsHelpFormatter(HelpFormatter):
+
+ def _get_help_string(self, action):
+ help = action.help
+ if '%(default)' not in action.help:
+ if action.default is not SUPPRESS:
+ defaulting_nargs = [OPTIONAL, ZERO_OR_MORE]
+ if action.option_strings or action.nargs in defaulting_nargs:
+ help += ' (default: %(default)s)'
+ return help
+
+
# =====================
# Options and Arguments
# =====================
|