diff Lib/argparse.py @ 63691:23c089dc5cff 2.7

Merged revisions 83675 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r83675 | r.david.murray | 2010-08-03 13:56:09 -0400 (Tue, 03 Aug 2010) | 12 lines #9444: use first of prefix_chars for help opt instead of raising error An argparse option parser created with a prefix_chars that did not include a '-' would happily add -h and --help options, and then throw an error when it tried to format the help because the - was an invalid prefix character. This patch makes it use the first character of prefix_chars as the character for the help options if and only if '-' is not one of the valid prefix_chars. Fix by Theodore Turocy, unit tests by Catherine Devlin. ........
author R. David Murray <rdmurray@bitdance.com>
date Tue, 03 Aug 2010 18:14:01 +0000
parents e64ea1619820
children 493a2d407c94
line wrap: on
line diff
--- a/Lib/argparse.py	Tue Aug 03 16:54:19 2010 +0000
+++ b/Lib/argparse.py	Tue Aug 03 18:14:01 2010 +0000
@@ -1563,13 +1563,16 @@
 
         # add help and version arguments if necessary
         # (using explicit default to override global argument_default)
+        default_prefix = '-' if '-' in prefix_chars else prefix_chars[0]
         if self.add_help:
             self.add_argument(
-                '-h', '--help', action='help', default=SUPPRESS,
+                default_prefix+'h', default_prefix*2+'help',
+                action='help', default=SUPPRESS,
                 help=_('show this help message and exit'))
         if self.version:
             self.add_argument(
-                '-v', '--version', action='version', default=SUPPRESS,
+                default_prefix+'v', default_prefix*2+'version',
+                action='version', default=SUPPRESS,
                 version=self.version,
                 help=_("show program's version number and exit"))