summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorsteven.bethard <devnull@localhost>2009-07-26 14:59:44 +0000
committersteven.bethard <devnull@localhost>2009-07-26 14:59:44 +0000
commit25d79f58974cc14f475a4762926981e247c9f70c (patch)
tree92214fd0ee60b4cb7d35ca84f34450952fc4d8f0 /doc
parent8a09594f57b03fa145267e17761940257554ab29 (diff)
downloadargparse-25d79f58974cc14f475a4762926981e247c9f70c.tar.gz
Allow subparsers to take title= and description= parameters.
Diffstat (limited to 'doc')
-rw-r--r--doc/source/other-methods.rst20
1 files changed, 20 insertions, 0 deletions
diff --git a/doc/source/other-methods.rst b/doc/source/other-methods.rst
index 5934554..7d9f33e 100644
--- a/doc/source/other-methods.rst
+++ b/doc/source/other-methods.rst
@@ -129,7 +129,27 @@ Sub-commands
optional arguments:
-h, --help show this help message and exit
--baz {X,Y,Z} baz help
+
+ 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::
+ >>> parser = argparse.ArgumentParser()
+ >>> subparsers = parser.add_subparsers(title='subcommands',
+ ... description='valid subcommands',
+ ... help='additional help')
+ >>> subparsers.add_parser('foo')
+ >>> subparsers.add_parser('bar')
+ >>> parser.parse_args(['-h'])
+ usage: [-h] {foo,bar} ...
+
+ optional arguments:
+ -h, --help show this help message and exit
+
+ subcommands:
+ valid subcommands
+
+ {foo,bar} additional help
+
+
One particularly effective way of handling sub-commands is to combine the use of the :meth:`add_subparsers` method with calls to :meth:`set_defaults` so that each subparser knows which Python function it should execute. For example::
>>> # sub-command functions