Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(97529)

Unified Diff: Doc/library/argparse.rst

Issue 9253: argparse: optional subparsers
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Lib/argparse.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Doc/library/argparse.rst Tue Apr 09 17:23:27 2013 +0200
+++ b/Doc/library/argparse.rst Fri Apr 12 22:49:30 2013 -0700
@@ -1452,7 +1452,26 @@
Sub-commands
^^^^^^^^^^^^
-.. method:: ArgumentParser.add_subparsers()
+.. method:: ArgumentParser.add_subparsers([title], [description], [prog], [dest], \
+ [required], [help], [metavar])
+
+ Create an action object which parses a command-line argument as a choice
+ from a set of parser sub-commands. The keyword arguments include a subset of
+ those accepted by :meth:`ArgumentParser.add_argument`.
+
+ * title_ - If defined, display the sub-command choices as an argument group.
+
+ * `description` - Description of the argument group.
+
+ * `prog` - Usage prefix in the subparser help output (default uses the parser prog_).
+
+ * dest_ - :class:`Namespace` attribute to hold the sub-command name (default ``argparse.SUPPRESS``).
+
+ * required_ - Whether or not the command-line option may be omitted (default ``True``).
+
+ * help_ - A brief description of subparser group.
+
+ * metavar_ - A name for the sub-command in the usage message.
Many programs split up their functionality into a number of sub-commands,
for example, the ``svn`` program can invoke sub-commands like ``svn
@@ -1492,7 +1511,8 @@
command line (and not any other subparsers). So in the example above, when
the ``a`` command is specified, only the ``foo`` and ``bar`` attributes are
present, and when the ``b`` command is specified, only the ``foo`` and
- ``baz`` attributes are present.
+ ``baz`` attributes are present. In this example, all argument strings after
+ subparser name ('a' or 'b') are parsed by that subparser.
Similarly, when a help message is requested from a subparser, only the help
for that particular parser will be printed. The help message will not
@@ -1530,6 +1550,8 @@
-h, --help show this help message and exit
--baz {X,Y,Z} baz help
+.. _title:
+
The :meth:`add_subparsers` method also supports ``title`` and ``description``
keyword arguments. When either is present, the subparser's commands will
appear in their own group in the help output. For example::
« no previous file with comments | « no previous file | Lib/argparse.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+