Skip to content
Myr

parameters.rst

This file

Path

docs/parameters.rst

56 lines · 2.1 KiB

Last changed by

Rewrite first half of options docs (#2825)Rowlando13before adoption82089af

History of this file

Take it

1Parameters2==========34.. currentmodule:: click56Click supports only two principle types of parameters for scripts (by design): options and arguments.78Options9----------------1011*   Are optional.12*   Recommended to use for everything except subcommands, urls, or files.13*   Can take a fixed number of arguments. The default is 1. They may be specified multiple times using :ref:`multiple-options`.14*   Are fully documented by the help page.15*   Have automatic prompting for missing input.16*   Can act as flags (boolean or otherwise).17*   Can be pulled from environment variables.1819Arguments20----------------2122*   Are optional with in reason, but not entirely so.23*   Recommended to use for subcommands, urls, or files.24*   Can take an arbitrary number of arguments.25*   Are not fully documented by the help page since they may be too specific to be automatically documented.  For more see :ref:`documenting-arguments`.26*   Can be pulled from environment variables but only explicitly named ones. For more see :ref:`environment-variables`.2728On each principle type you can specify :ref:`parameter-types`. Specifying these types helps Click add details to your help pages and help with the handling of those types.2930.. _parameter_names:3132Parameter Names33---------------3435Parameters (options and arguments) have a name that will be used as36the Python argument name when calling the decorated function with37values.3839.. click:example::4041    @click.command()42    @click.argument('filename')43    @click.option('-t', '--times', type=int)44    def multi_echo(filename, times):45        """Print value filename multiple times."""46        for x in range(times):47            click.echo(filename)4849In the above example the argument's name is ``filename``. The name must match the python arg name. To provide a different name for use in help text, see :ref:`doc-meta-variables`.50The option's names are ``-t`` and ``--times``. More names are available for options and are covered in :ref:`options`.5152And what it looks like when run:5354.. click:run::5556    invoke(multi_echo, ['--times=3', 'index.txt'], prog_name='multi_echo')