]> granicus.if.org Git - python/commitdiff
Issue #13605: add documentation for nargs=argparse.REMAINDER
authorSandro Tosi <sandro.tosi@gmail.com>
Thu, 19 Jan 2012 20:59:34 +0000 (21:59 +0100)
committerSandro Tosi <sandro.tosi@gmail.com>
Thu, 19 Jan 2012 20:59:34 +0000 (21:59 +0100)
Doc/library/argparse.rst

index 9488466fcf5fa09d307b52d3c126e1d9e6c85643..6e8bff1b8d922efd565c2a3dfb8975b9e9ab88f7 100644 (file)
@@ -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.