@@ -1771,7 +1771,7 @@ Subcommands
17711771 >>> parser.parse_args(['--foo', 'b', '--baz', 'Z'])
17721772 Namespace(baz='Z', foo=True)
17731773
1774- Note that the object returned by :meth: `parse_args ` will only contain
1774+ Note that the object returned by :meth: `~ArgumentParser. parse_args ` will only contain
17751775 attributes for the main parser and the subparser that was selected by the
17761776 command line (and not any other subparsers). So in the example above, when
17771777 the ``a `` command is specified, only the ``foo `` and ``bar `` attributes are
@@ -1814,7 +1814,7 @@ Subcommands
18141814 -h, --help show this help message and exit
18151815 --baz {X,Y,Z} baz help
18161816
1817- The :meth: `add_subparsers ` method also supports ``title `` and ``description ``
1817+ The :meth: `~ArgumentParser. add_subparsers ` method also supports ``title `` and ``description ``
18181818 keyword arguments. When either is present, the subparser's commands will
18191819 appear in their own group in the help output. For example::
18201820
@@ -1835,34 +1835,8 @@ Subcommands
18351835
18361836 {foo,bar} additional help
18371837
1838- Furthermore, :meth: `~_SubParsersAction.add_parser ` supports an additional
1839- *aliases * argument,
1840- which allows multiple strings to refer to the same subparser. This example,
1841- like ``svn ``, aliases ``co `` as a shorthand for ``checkout ``::
1842-
1843- >>> parser = argparse.ArgumentParser()
1844- >>> subparsers = parser.add_subparsers()
1845- >>> checkout = subparsers.add_parser('checkout', aliases=['co'])
1846- >>> checkout.add_argument('foo')
1847- >>> parser.parse_args(['co', 'bar'])
1848- Namespace(foo='bar')
1849-
1850- :meth: `~_SubParsersAction.add_parser ` supports also an additional
1851- *deprecated * argument, which allows to deprecate the subparser.
1852-
1853- >>> import argparse
1854- >>> parser = argparse.ArgumentParser(prog = ' chicken.py' )
1855- >>> subparsers = parser.add_subparsers()
1856- >>> run = subparsers.add_parser(' run' )
1857- >>> fly = subparsers.add_parser(' fly' , deprecated = True )
1858- >>> parser.parse_args([' fly' ]) # doctest: +SKIP
1859- chicken.py: warning: command 'fly' is deprecated
1860- Namespace()
1861-
1862- .. versionadded :: 3.13
1863-
18641838 One particularly effective way of handling subcommands is to combine the use
1865- of the :meth: `add_subparsers ` method with calls to :meth: `set_defaults ` so
1839+ of the :meth: `~ArgumentParser. add_subparsers ` method with calls to :meth: `~ArgumentParser. set_defaults ` so
18661840 that each subparser knows which Python function it should execute. For
18671841 example::
18681842
@@ -1898,12 +1872,12 @@ Subcommands
18981872 >>> args.func(args)
18991873 ((XYZYX))
19001874
1901- This way, you can let :meth: `parse_args ` do the job of calling the
1875+ This way, you can let :meth: `~ArgumentParser. parse_args ` do the job of calling the
19021876 appropriate function after argument parsing is complete. Associating
19031877 functions with actions like this is typically the easiest way to handle the
19041878 different actions for each of your subparsers. However, if it is necessary
19051879 to check the name of the subparser that was invoked, the ``dest `` keyword
1906- argument to the :meth: `add_subparsers ` call will work::
1880+ argument to the :meth: `~ArgumentParser. add_subparsers ` call will work::
19071881
19081882 >>> parser = argparse.ArgumentParser()
19091883 >>> subparsers = parser.add_subparsers(dest='subparser_name')
@@ -1922,6 +1896,43 @@ Subcommands
19221896 the main parser.
19231897
19241898
1899+ .. method :: _SubParsersAction.add_parser(name, *, help=None, aliases=None, \
1900+ deprecated=False, **kwargs)
1901+
1902+ Create and return a new :class: `ArgumentParser ` object for the
1903+ subcommand *name *.
1904+
1905+ The *name * argument is the name of the sub-command.
1906+
1907+ The *help * argument provides a short description for this sub-command.
1908+
1909+ The *aliases * argument allows providing alternative names for this
1910+ sub-command. For example::
1911+
1912+ >>> parser = argparse.ArgumentParser()
1913+ >>> subparsers = parser.add_subparsers()
1914+ >>> checkout = subparsers.add_parser('checkout', aliases=['co'])
1915+ >>> checkout.add_argument('foo')
1916+ >>> parser.parse_args(['co', 'bar'])
1917+ Namespace(foo='bar')
1918+
1919+ The *deprecated * argument, if ``True ``, marks the sub-command as
1920+ deprecated and will issue a warning when used. For example::
1921+
1922+ >>> parser = argparse.ArgumentParser(prog='chicken.py')
1923+ >>> subparsers = parser.add_subparsers()
1924+ >>> fly = subparsers.add_parser('fly', deprecated=True)
1925+ >>> args = parser.parse_args(['fly'])
1926+ chicken.py: warning: command 'fly' is deprecated
1927+ Namespace()
1928+
1929+ All other keyword arguments are passed directly to the
1930+ :class: `!ArgumentParser ` constructor.
1931+
1932+ .. versionadded :: 3.13
1933+ Added the *deprecated * parameter.
1934+
1935+
19251936FileType objects
19261937^^^^^^^^^^^^^^^^
19271938
0 commit comments