From 964f4b833e9390645cd3c4db89570b314e19c0e5 Mon Sep 17 00:00:00 2001 From: Patricio Paez Date: Mon, 23 Jan 2023 13:05:39 -0600 Subject: [PATCH] Document nargs='...' --- Doc/library/argparse.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 475cac70291e9a..61aef7b82fa731 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1043,6 +1043,17 @@ If the ``nargs`` keyword argument is not provided, the number of arguments consu 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. +* ``'...'``. The remaining command-line args are gathered into a list, + including optional arguments. If there are no remaining arguments, + an empty list is returned. For example:: + + >>> parser = argparse.ArgumentParser() + >>> parser.add_argument('cmd') + >>> parser.add_argument('args', nargs='...') + >>> parser.parse_args('script.sh -v -n'.split()) + Namespace(cmd=['script.sh'], args=['-v', '-n']) + >>> parser.parse_args('script.sh'.split()) + Namespace(cmd=['script.sh'], args=[]) .. _const: