summaryrefslogtreecommitdiff
path: root/doc/source
diff options
context:
space:
mode:
authorsteven.bethard <devnull@localhost>2009-07-13 00:02:35 +0000
committersteven.bethard <devnull@localhost>2009-07-13 00:02:35 +0000
commitbe051b2738ef9e459651e3c75a24f0ce97374d0c (patch)
treea9b4516c18bae17149d6059fdfa9150bc4779201 /doc/source
parent85f71279479f91b17f2eb9e79c38d576538fa242 (diff)
downloadargparse-be051b2738ef9e459651e3c75a24f0ce97374d0c.tar.gz
Add ArgumentDefaultsHelpFormatter.
Diffstat (limited to 'doc/source')
-rw-r--r--doc/source/ArgumentParser.rst21
1 files changed, 21 insertions, 0 deletions
diff --git a/doc/source/ArgumentParser.rst b/doc/source/ArgumentParser.rst
index 1bf5e63..8a103dd 100644
--- a/doc/source/ArgumentParser.rst
+++ b/doc/source/ArgumentParser.rst
@@ -176,6 +176,10 @@ Sometimes, several parsers share a common set of arguments. Rather than repeatin
formatter_class
---------------
+ArgumentParser objects allow the help formatting to be customized by specifying an alternate formatting class.
+Currently, there are three such classes: ``argparse.RawDescriptionHelpFormatter``, ``argparse.RawTextHelpFormatter`` and ``argparse.ArgumentDefaultsHelpFormatter``.
+The first two allow more control over how textual descriptions are displayed, while the last automatically adds information about argument default values.
+
By default, ArgumentParser objects line-wrap the description_ and epilog_ texts in command-line help messages::
>>> parser = argparse.ArgumentParser(
@@ -224,6 +228,23 @@ When you have description_ and epilog_ that is already correctly formatted and s
If you want to maintain whitespace for all sorts of help text (including argument descriptions), you can use ``argparse.RawTextHelpFormatter``.
+The other formatter class available, ``argparse.ArgumentDefaultsHelpFormatter``, will add information about the default value of each of the arguments::
+
+ >>> parser = argparse.ArgumentParser(
+ ... prog='PROG',
+ ... formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+ >>> parser.add_argument('--foo', type=int, default=42, help='FOO!')
+ >>> parser.add_argument('bar', nargs='*', default=[1, 2, 3], help='BAR!')
+ >>> parser.print_help()
+ usage: PROG [-h] [--foo FOO] [bar [bar ...]]
+
+ positional arguments:
+ bar BAR! (default: [1, 2, 3])
+
+ optional arguments:
+ -h, --help show this help message and exit
+ --foo FOO FOO! (default: 42)
+
conflict_handler
----------------