diff options
author | R. David Murray <rdmurray@bitdance.com> | 2010-08-03 18:14:01 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2010-08-03 18:14:01 (GMT) |
commit | 1cbf78e040b1ddfe7a1520d21ea34e1098848713 (patch) | |
tree | 6a32364130570d6302f2b94aae36d0d72847ee97 /Doc | |
parent | 0f98128d6e9a2375bb560a58418e83ebd1996f2b (diff) | |
download | cpython-1cbf78e040b1ddfe7a1520d21ea34e1098848713.zip cpython-1cbf78e040b1ddfe7a1520d21ea34e1098848713.tar.gz cpython-1cbf78e040b1ddfe7a1520d21ea34e1098848713.tar.bz2 |
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.
........
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/argparse.rst | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index b3a1171..45eddca 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -203,8 +203,8 @@ argument to :class:`ArgumentParser`. add_help ^^^^^^^^ -By default, ArgumentParser objects add a ``-h/--help`` option which simply -displays the parser's help message. For example, consider a file named +By default, ArgumentParser objects add an option which simply displays +the parser's help message. For example, consider a file named ``myprogram.py`` containing the following code:: import argparse @@ -234,12 +234,27 @@ This can be achieved by passing ``False`` as the ``add_help=`` argument to optional arguments: --foo FOO foo help +The help option is typically ``-h/--help``. The exception to this is +if the ``prefix_chars=`` is specified and does not include ``'-'``, in +which case ``-h`` and ``--help`` are not valid options. In +this case, the first character in ``prefix_chars`` is used to prefix +the help options:: + + >>> parser = argparse.ArgumentParser(prog='PROG', prefix_chars='+/') + >>> parser.print_help() + usage: PROG [+h] + + optional arguments: + +h, ++help show this help message and exit + + prefix_chars ^^^^^^^^^^^^ Most command-line options will use ``'-'`` as the prefix, e.g. ``-f/--foo``. -Parsers that need to support additional prefix characters, e.g. for options +Parsers that need to support different or additional prefix +characters, e.g. for options like ``+f`` or ``/foo``, may specify them using the ``prefix_chars=`` argument to the ArgumentParser constructor:: |