parameters.md
This file
Path
docs/parameters.md
55 lines · 2.0 KiB · Markdown
Last changed by
Convert parameters file to md. (#2953)Rowlando13before adoptiona6cc378
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556(parameters)=
# Parameters
```{currentmodule} click```
Click supports only two principle types of parameters for scripts (by design): options and arguments.
## Options
- Are optional.- Recommended to use for everything except subcommands, urls, or files.- Can take a fixed number of arguments. The default is 1. They may be specified multiple times using {ref}`multiple-options`.- Are fully documented by the help page.- Have automatic prompting for missing input.- Can act as flags (boolean or otherwise).- Can be pulled from environment variables.
## Arguments
- Are optional with in reason, but not entirely so.- Recommended to use for subcommands, urls, or files.- Can take an arbitrary number of arguments.- Are not fully documented by the help page since they may be too specific to be automatically documented. For more see {ref}`documenting-arguments`.- Can be pulled from environment variables but only explicitly named ones. For more see {ref}`environment-variables`.
On 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.
(parameter-names)=
## Parameter Names
Parameters (options and arguments) have a name that will be used asthe Python argument name when calling the decorated function withvalues.
In the 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`.The option's names are `-t` and `--times`. More names are available for options and are covered in {ref}`options`.
```{eval-rst}.. click:example::
@click.command() @click.argument('filename') @click.option('-t', '--times', type=int) def multi_echo(filename, times): """Print value filename multiple times.""" for x in range(times): click.echo(filename)
.. click:run::
invoke(multi_echo, ['--times=3', 'index.txt'], prog_name='multi_echo')```