Skip to content
Myr

parameters.md

This file

Path

docs/parameters.md

55 lines · 2.0 KiB · Markdown

Last changed by

Merge `stable` into `main` after `CHANGES` rST to Markdown conversion (#3563)Kevin Deldyckebefore adoption8a1b1a3

History of this file

Take it

Convert parameters file to md. (#2953)Rowlando13before adoptiona6cc378

lines 1–21why, one step back
1(parameters)=
23# Parameters45```{currentmodule} click6```78Click supports only two principle types of parameters for scripts (by design): options and arguments.910## Options1112- Are optional.13- Recommended to use for everything except subcommands, urls, or files.14- Can take a fixed number of arguments. The default is 1. They may be specified multiple times using {ref}`multiple-options`.15- Are fully documented by the help page.16- Have automatic prompting for missing input.17- Can act as flags (boolean or otherwise).18- Can be pulled from environment variables.1920## Arguments21

Merge `stable` into `main` after `CHANGES` rST to Markdown conversion (#3563)Kevin Deldyckebefore adoption8a1b1a3

line 22why, one step back
22- Are optional within reason, but not entirely so.

Convert parameters file to md. (#2953)Rowlando13before adoptiona6cc378

lines 23–55why, one step back
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)=3132## Parameter Names3334Parameters (options and arguments) have a name that will be used as35the Python argument name when calling the decorated function with36values.3738In 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`.39The option's names are `-t` and `--times`. More names are available for options and are covered in {ref}`options`.4041```{eval-rst}42.. click:example::4344 @click.command()45 @click.argument('filename')46 @click.option('-t', '--times', type=int)47 def multi_echo(filename, times):48 """Print value filename multiple times."""49 for x in range(times):50 click.echo(filename)5152.. click:run::5354 invoke(multi_echo, ['--times=3', 'index.txt'], prog_name='multi_echo')55```