summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSandro Tosi <sandro.tosi@gmail.com>2012-01-19 21:59:34 +0100
committerSandro Tosi <sandro.tosi@gmail.com>2012-01-19 21:59:34 +0100
commit10f047dca85baf37eaa69a13e5a98c2d27a41094 (patch)
tree2debc0f92962bb0bb39b18e9979e376cee34f70e
parentd53abd3154105c9017bc47112119f4279d6a7986 (diff)
downloadcpython-git-10f047dca85baf37eaa69a13e5a98c2d27a41094.tar.gz
Issue #13605: add documentation for nargs=argparse.REMAINDER
-rw-r--r--Doc/library/argparse.rst11
1 files changed, 11 insertions, 0 deletions
diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
index 9488466fcf..6e8bff1b8d 100644
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -838,6 +838,17 @@ values are:
usage: PROG [-h] foo [foo ...]
PROG: error: too few arguments
+* ``argparse.REMAINDER``. All the remaining command-line arguments
+ are gathered into a lits. This is commonly useful for command line
+ utilities that dispatch to other command line utilities.
+
+ >>> parser = argparse.ArgumentParser(prog='PROG')
+ >>> parser.add_argument('--foo')
+ >>> parser.add_argument('command')
+ >>> parser.add_argument('args', nargs=argparse.REMAINDER)
+ >>> print parser.parse_args('--foo B XX YY ZZ'.split())
+ Namespace(args=['YY', 'ZZ'], command='XX', foo='B')
+
If the ``nargs`` keyword argument is not provided, the number of arguments consumed
is determined by the action_. Generally this means a single command-line argument
will be consumed and a single item (not a list) will be produced.