Skip to content
Myr

Option naming: add test and documentation for existing functionality

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Eric L Frederich · committed by Eric L Frederich · parent 945b4d3 · Browse files · 2 files+19 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+19 added−5 removed

  • tests:+7 added−3 removed
  • other:+12 added−2 removed

2 files+19 added−5 removed

modified:docs/options.rst+12 added-2 removed
14 unmodified lines
1516The most basic option is a value option. These options accept one17argument which is a value. If no type is provided, the type of the default18value is used. If no default value is provided, the type is assumed to be19:data:`STRING`. By default, the name of the parameter is the first long20option defined; otherwise the first short one is used.19:data:`STRING`. Unless a name is explicitly specified, the name of the20parameter is the first long option defined; otherwise the first short one is21used.2223.. click:example::2425 @click.command()26 @click.option('--n', default=1)27 def dots(n):28 click.echo('.' * n)2930.. click:example::3132 # How to use a Python reserved word such as `from` as a parameter33 @click.command()34 @click.option('--from', '-f', '_from')35 @click.option('--to', '-t')36 def reserved_param_name(_from, to):37 click.echo('from %s to %s' % (_from, to))3839And on the command line:4041.. click:run::42
663 unmodified lines
modified:tests/test_options.py+7 added-3 removed
343 unmodified lines
344 (['-a', '-b', '-c'], 'a'),345 (['-c', '-b', '-a'], 'c'),346 (['-a', '--apple', '-b', '--banana', '-c', '--cantaloupe'], 'apple'),347 (['-c', '-a', '--cantaloupe', '-b', '--banana', '--apple'], 'cantaloupe'),348 (['--from', '-f', '_from'], '_from'),349 (['--return', '-r', '_ret'], '_ret'),350])349def test_multiple_long_options(runner, option_args, expected):351def test_option_names(runner, option_args, expected):352353 @click.command()354 @click.option(*option_args, is_flag=True)355 def cmd(**kwargs):356 click.echo(str(kwargs[expected]))357358 assert cmd.params[0].name == expected359360 for form in option_args:361 if form.startswith('-'):358 result = runner.invoke(cmd, [form])359 assert result.output == 'True\n'362 result = runner.invoke(cmd, [form])363 assert result.output == 'True\n'