summaryrefslogtreecommitdiff
path: root/argparse.py
diff options
context:
space:
mode:
authorsteven.bethard <devnull@localhost>2009-09-13 00:01:52 +0000
committersteven.bethard <devnull@localhost>2009-09-13 00:01:52 +0000
commit6964050e4ae3122748b8fc207f1a44aa6a917d1a (patch)
tree0e9a26e017f433c4b0391e71daf8ad64c165dc41 /argparse.py
parentd1ce37550e67bc777504f3cde9a2c2c5bd7951ec (diff)
downloadargparse-6964050e4ae3122748b8fc207f1a44aa6a917d1a.tar.gz
Fix a bug that was preventing % from being used in help messages.
Diffstat (limited to 'argparse.py')
-rw-r--r--argparse.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/argparse.py b/argparse.py
index 75a9043..ce1adb9 100644
--- a/argparse.py
+++ b/argparse.py
@@ -306,7 +306,7 @@ class HelpFormatter(object):
# Help-formatting methods
# =======================
def format_help(self):
- help = self._root_section.format_help() % dict(prog=self._prog)
+ help = self._root_section.format_help()
if help:
help = self._long_break_matcher.sub('\n\n', help)
help = help.strip('\n') + '\n'
@@ -321,9 +321,13 @@ class HelpFormatter(object):
if prefix is None:
prefix = _('usage: ')
+ # if usage is specified, use that
+ if usage is not None:
+ usage = usage % dict(prog=self._prog)
+
# if no optionals or positionals are available, usage is just prog
- if usage is None and not actions:
- usage = '%(prog)s'
+ elif usage is None and not actions:
+ usage = '%(prog)s' % dict(prog=self._prog)
# if optionals and positionals are available, calculate usage
elif usage is None: