up:: [[Click MOC]] ## Quickstart ```python @click.command() @click.option('-c', '--count', default=1, help='number of greetings') @click.argument('name') def hello(count, name): for x in range(count): click.echo(f"Hello {name}!") ``` ^jaloxu What it looks like: ```shell $ python hello.py --help Usage: hello.py [OPTIONS] NAME Options: --count INTEGER number of greetings --help Show this message and exit. ``` ## Arguments vs. Options Arguments and options are the two parameter types supported by Click.[^1] ### Arguments Arguments do less than options, but can do some things that options can not, such as take in an arbitrary number of arguments. They are also always required. > [!CAUTION] Argument help? > Unlike options, arguments do not take the "help" parameter. Giving an argument one will result in this error: `TypeError: __init__() got an unexpected keyword argument 'help'` ^[[Source](https://stackoverflow.com/questions/31173308/why-does-my-use-of-click-argument-produce-got-an-unexpected-keyword-argument-h)] ^[[[Research Data Migration#^ay55x3|Original note]]] ### Options Options represent optional parameters and are uniquely positioned to provide some special behaviors by default, such as: - acting as flags - prompting for missing input - getting values from environment variables As seen in the [[Click Quickstart and Reference#^jaloxu|quickstart]], options can take many names[^2]. If you provide a name with hyphens and that is passed to the function, the hyphens will be converted to underscores. The following steps are used to determine which name gets passed to the Python function: 1. if a name isn't prefixed, that's the Python argument name 2. if there is at least one name prefixed with two dashes, the first one is used as the name 3. if none of these are satisfied, then the first name prefixed with a single dash is used ## Sources ![[Research Data Migration#^rjamex]] ![[Research Data Migration#^y4bmf8]] ![[Research Data Migration#^j34svv]] [^1]: [Parameters in Click](https://click.palletsprojects.com/en/8.1.x/parameters/) [^2]: [Parameter name resolution in Click](https://click.palletsprojects.com/en/8.1.x/parameters/#parameter-names)