Skip to content

Commit 53031db

Browse files
Done the changes
1 parent 312aa0f commit 53031db

File tree

1 file changed

+31
-77
lines changed

1 file changed

+31
-77
lines changed

Doc/library/argparse.rst

Lines changed: 31 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,7 @@ The Namespace object
16561656
Other utilities
16571657
---------------
16581658

1659-
Subcommands
1659+
Sub-commands
16601660
^^^^^^^^^^^^
16611661

16621662
.. method:: ArgumentParser.add_subparsers(*, [title], [description], [prog], \
@@ -1674,50 +1674,46 @@ Subcommands
16741674
called with no arguments and returns a special action object. This object
16751675
has a single method, :meth:`~_SubParsersAction.add_parser`:
16761676

1677-
.. method:: _SubParsersAction.add_parser(name, *, help=None, aliases=None, deprecated=False, **kwargs)
1677+
.. method:: _SubParsersAction.add_parser(name, *, help=None, aliases=None, deprecated=False, **kwargs)
16781678

1679-
Creates and returns a new :class:`!ArgumentParser` object for the
1680-
subcommand *name*.
1679+
Creates and returns a new :class:`!ArgumentParser` object for the
1680+
subcommand *name*.
16811681

1682-
The *name* argument is the name of the subcommand.
1683-
The *help* argument provides a short description for this subcommand. If provided, it will be listed next to the command in the main parser's help message (e.g., ``PROG --help``).
1682+
The *name* argument is the name of the sub-command.
16841683

1685-
The *aliases* argument allows to provide a sequence of strings that can be used as alternative names for this subcommand (e.g., ``aliases=['r']`` for a ``'run'`` command).
1684+
The *help* argument provides a short description for this sub-command.
1685+
If provided, it will be listed next to the command in the main parser’s
1686+
help message (e.g., ``PROG --help``).
16861687

1687-
The *deprecated* argument, if :const:`True`, marks the subcommand as deprecated, which typically issues a warning when used.
1688+
The *aliases* argument allows providing alternative names for this
1689+
sub-command.
16881690

1689-
All other keyword arguments are passed directly to the
1690-
:class:`!ArgumentParser` constructor.
1691+
The *deprecated* argument, if ``True``, marks the sub-command as
1692+
deprecated and will issue a warning when used.
16911693

1692-
Description of parameters:
1694+
All other keyword arguments are passed directly to the
1695+
:class:`!ArgumentParser` constructor.
16931696

1694-
* *title* - title for the subparser group in help output; by default
1695-
"subcommands" if description is provided, otherwise uses title for
1696-
positional arguments
1697+
Examples
1698+
~~~~~~~~
16971699

1698-
* *description* - description for the subparser group in help output, by
1699-
default ``None``
1700+
Using aliases::
17001701

1701-
* *prog* - usage information that will be displayed with subcommand help,
1702-
by default the name of the program and any positional arguments before the
1703-
subparser argument
1704-
1705-
* *parser_class* - class which will be used to create subparser instances, by
1706-
default the class of the current parser (e.g. :class:`ArgumentParser`)
1707-
1708-
* action_ - the basic type of action to be taken when this argument is
1709-
encountered at the command line
1710-
1711-
* dest_ - name of the attribute under which subcommand name will be
1712-
stored; by default ``None`` and no value is stored
1713-
1714-
* required_ - Whether or not a subcommand must be provided, by default
1715-
``False`` (added in 3.7)
1702+
>>> parser = argparse.ArgumentParser()
1703+
>>> subparsers = parser.add_subparsers()
1704+
>>> checkout = subparsers.add_parser('checkout', aliases=['co'])
1705+
>>> checkout.add_argument('foo')
1706+
>>> parser.parse_args(['co', 'bar'])
1707+
Namespace(foo='bar')
17161708

1717-
* help_ - help for subparser group in help output, by default ``None``
1709+
Using deprecated::
17181710

1719-
* metavar_ - string presenting available subcommands in help; by default it
1720-
is ``None`` and presents subcommands in form {cmd1, cmd2, ..}
1711+
>>> parser = argparse.ArgumentParser(prog='chicken.py')
1712+
>>> subparsers = parser.add_subparsers()
1713+
>>> fly = subparsers.add_parser('fly', deprecated=True)
1714+
>>> parser.parse_args(['fly']) # doctest: +SKIP
1715+
chicken.py: warning: command 'fly' is deprecated
1716+
Namespace()
17211717

17221718
Some example usage::
17231719

@@ -1804,48 +1800,6 @@ Subcommands
18041800

18051801
{foo,bar} additional help
18061802

1807-
.. method:: _SubParsersAction.add_parser(name, *, help=None, aliases=None, deprecated=False, **kwargs)
1808-
1809-
Creates and returns a new :class:`!ArgumentParser` object for the
1810-
subcommand name.
1811-
1812-
The name argument is the name of the subcommand.
1813-
1814-
The help argument provides a short description for this subcommand.
1815-
If provided, it will be listed next to the command in the main
1816-
parser’s help message (e.g., ``PROG --help``).
1817-
1818-
The aliases argument allows you to provide a sequence of strings
1819-
that can be used as alternative names for this subcommand
1820-
(e.g., ``aliases=['co']`` for a ``'checkout'`` command).
1821-
1822-
The deprecated argument allows you to mark the subcommand as
1823-
deprecated. When a deprecated subcommand is used, :mod:`argparse`
1824-
will emit a warning.
1825-
1826-
This returned :class:`!ArgumentParser`
1827-
object can be modified as usual.
1828-
1829-
*Examples*
1830-
1831-
Using aliases::
1832-
1833-
>>> parser = argparse.ArgumentParser()
1834-
>>> subparsers = parser.add_subparsers()
1835-
>>> checkout = subparsers.add_parser('checkout', aliases=['co'])
1836-
>>> checkout.add_argument('foo')
1837-
>>> parser.parse_args(['co', 'bar'])
1838-
Namespace(foo='bar')
1839-
1840-
Using deprecated::
1841-
1842-
>>> parser = argparse.ArgumentParser(prog='chicken.py')
1843-
>>> subparsers = parser.add_subparsers()
1844-
>>> fly = subparsers.add_parser('fly', deprecated=True)
1845-
>>> parser.parse_args(['fly']) # doctest: +SKIP
1846-
chicken.py: warning: command 'fly' is deprecated
1847-
Namespace()
1848-
18491803
One particularly effective way of handling subcommands is to combine the use
18501804
of the :meth:`~ArgumentParser.add_subparsers` method with calls to :meth:`~ArgumentParser.set_defaults` so
18511805
that each subparser knows which Python function it should execute. For
@@ -2270,7 +2224,7 @@ Registering custom types or actions
22702224

22712225
Sometimes it's desirable to use a custom string in error messages to provide
22722226
more user-friendly output. In these cases, :meth:`!register` can be used to
2273-
register custom actions or types with a parser anto reference the
2227+
register custom actions or types with a parser allows you to reference the
22742228
type by their registered name instead of their callable name.
22752229

22762230
The :meth:`!register` method accepts three arguments - a *registry_name*,

0 commit comments

Comments
 (0)