summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2016-08-18 20:23:48 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2016-08-18 20:23:48 (GMT)
commitef948cd058180a2fb38d792c912c9b14d190d6c7 (patch)
tree58a73f353df03109da2d307e3ba4d972c1999a6e /Doc
parent97c1adf3935234da716d3289b85f72dcd67e90c2 (diff)
downloadcpython-ef948cd058180a2fb38d792c912c9b14d190d6c7.zip
cpython-ef948cd058180a2fb38d792c912c9b14d190d6c7.tar.gz
cpython-ef948cd058180a2fb38d792c912c9b14d190d6c7.tar.bz2
Closes #12713: Allowed abbreviation of subcommands in argparse.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/argparse.rst12
1 files changed, 12 insertions, 0 deletions
diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
index 995c4ee..d285c66 100644
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -1668,6 +1668,18 @@ Sub-commands
>>> parser.parse_args(['co', 'bar'])
Namespace(foo='bar')
+ argparse supports non-ambiguous abbreviations of subparser names.
+
+ For example, the following three calls are all supported
+ and do the same thing, as the abbreviations used are not ambiguous::
+
+ >>> parser.parse_args(['checkout', 'bar'])
+ Namespace(foo='bar')
+ >>> parser.parse_args(['check', 'bar'])
+ Namespace(foo='bar')
+ >>> parser.parse_args(['che', 'bar'])
+ Namespace(foo='bar')
+
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