]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Clean-up the argparse docs quick links table (GH-91726)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Wed, 20 Apr 2022 06:21:54 +0000 (01:21 -0500)
committerGitHub <noreply@github.com>
Wed, 20 Apr 2022 06:21:54 +0000 (01:21 -0500)
Doc/library/argparse.rst

index 425409db3cb751f2dd09709b4b71c91613d79a6c..7c206370f543255cb945d18ff7665955d829aac9 100644 (file)
@@ -26,73 +26,51 @@ module also automatically generates help and usage messages and issues errors
 when users give the program invalid arguments.
 
 
-Summary
--------
-
 Core Functionality
-^^^^^^^^^^^^^^^^^^
+------------------
 
 The :mod:`argparse` module's support for command-line interfaces is built
-from the following:
-
-The :class:`argparse.ArgumentParser` creates a new :class:`ArgumentParser`
-object. Commonly used arguments include prog_, description_, and
-formatter_class_. For example, the user can create an instance of
-:class:`ArgumentParser` through the following::
-
-   >>> parser = argparse.ArgumentParser(prog='PROG', description='DESC',
-   ...                                  formatter_class=argparse.RawDescriptionHelpFormatter)
-
-The :func:`ArgumentParser.add_argument` is a function that is used
-to define how a single command-line argument should be parsed. Commonly used
-arguments include `name or flags`_, action_, default_, type_, required_,
-and help_. An example of the function :func:`ArgumentParser.add_argument`
-is as follows::
-
-   >>> parser.add_argument('-v', '--verbose', action='store_true',
-   ...                     help='Show various debugging information')
+around an instance of :class:`argparse.ArgumentParser`.  It is a container for
+argument specifications and has options that apply the parser as whole::
 
+   parser = argparse.ArgumentParser(
+                 prog = 'ProgramName',
+                 description = 'What the program does',
+                 epilog = 'Text at the bottom of help')
 
-Basic Usage of :func:`add_argument`
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+The :func:`ArgumentParser.add_argument` function attaches individual argument
+specifications to the parser.  It supports positional arguments, options that
+accept values, and on/off flags::
 
+   parser.add_argument('filename')           # positional argument
+   parser.add_argument('-c', '--count')      # option that takes value
+   parser.add_argument('-v', '--verbose',
+                       action='store_true')  # on/off flag
 
-**Name or Flags Type**
+The :func:`ArgumentParser.parse_args` function runs the parser and puts
+the extracted data in a :class:`argparse.Namespace` object::
 
-====================== ===========================
-Type                   Example
-====================== ===========================
-Positional             ``'foo'``
-Optional               ``'-v'``, ``'--verbose'``
-====================== ===========================
+   args = parser.parse_args()
+   print(args.filename, args.count, args.verbose)
 
 
-**Basic Arguments:**
+Quick Links for add_argument()
+------------------------------
 
-====================== =========================================================== =========================================================================================================================
-Name                   Description                                                 Keywords
-====================== =========================================================== =========================================================================================================================
-action_                Specifies how an argument should be handled                 ``'store'``, ``'store_const'``, ``'store_true'``, ``'append'``, ``'append_const'``, ``'count'``, ``'help'``, ``'version'``
+====================== =========================================================== ==========================================================================================================================
+Name                   Description                                                 Values
+====================== =========================================================== ==========================================================================================================================
+action_                Specify how an argument should be handled                   ``'store'``, ``'store_const'``, ``'store_true'``, ``'append'``, ``'append_const'``, ``'count'``, ``'help'``, ``'version'``
+choices_               Limit values to specific set of choices                     ``['foo', 'bar']``, ``range(1, 10)``, or an object that supports ``in`` operator
+const_                 Store a constant value
 default_               Default value used when an argument is not provided
-type_                  Automatically converts an argument to the given type        :class:`int`, :class:`float`, :class:`bool`, ``argparse.FileType('w')``, ``callable function``
-help_                  Help message of an argument
-====================== =========================================================== =========================================================================================================================
-
-
-
-**Advanced Arguments:**
-
-====================== =========================================================== =======================================================================================================================
-Name                   Description                                                 Keywords
-====================== =========================================================== =======================================================================================================================
-nargs_                 Associates a single action with the number of arguments     ``N`` (:class:`int`), ``'?'``, ``'*'``, ``'+'``, ``argparse.REMAINDER``
-const_                 Stores constant values of names or flags
-choices_               A container that lists the possible values                  ``['foo', 'bar']``, ``range(1, 10)``, Any object that supports ``in`` operator
-required_              Indicates if an optional argument is required or not        ``True``, ``False``
-metavar_               An alternative display name for the argument
-dest_                  Specifies name of attribute to be used in ``parse_args()``
-====================== =========================================================== =======================================================================================================================
-
+dest_                  Specify the attribute name in result namespace
+help_                  Help message for an argument
+metavar_               Alternate display name for the argument as shown in help
+nargs_                 Number of times the argument can be used                    ``N`` (:class:`int`), ``'?'``, ``'*'``, ``'+'``, ``argparse.REMAINDER``
+required_              Indicate whether an optional argument is required or not    ``True``, ``False``
+type_                  Automatically convert an argument to the given type         :class:`int`, :class:`float`, ``argparse.FileType('w')``, or any callable function
+====================== =========================================================== ==========================================================================================================================
 
 
 Example