Skip to content
Myr

Disallow empty options to help users find options that should be arguments.

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

authored by Armin Ronacher · committed by Armin Ronacher · parent 9afe871 · Browse files · 3 files+22 added−0 removed
This commit

State

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

Diff stats

3 files+22 added−0 removed

  • tests:+13 added−0 removed
  • other:+9 added−0 removed

3 files+22 added−0 removed

modified:click/core.py+5 added
1160 unmodified lines
1161 if not expose_value:1162 return None, opts, secondary_opts1163 raise TypeError('Could not determine name for option')11641165 if not opts and not secondary_opts:1166 raise TypeError('No options defined but a name was passed (%s). '1167 'Did you mean to declare an argument instead '1168 'of an option?' % name)11691170 return name, opts, secondary_opts11711172 def add_to_parser(self, parser, ctx):1173 kwargs = {
163 unmodified lines
modified:tests/test_options.py+13 added
19 unmodified lines
20 assert re.search(r'\+\+foo\s+das foo', result.output) is not None21 assert re.search(r'--bar\s+das bar', result.output) is not None222324def test_invalid_option(runner):25 try:26 @click.command()27 @click.option('foo')28 def cli(foo):29 pass30 except TypeError as e:31 assert 'No options defined but a name was passed (foo).' \32 in str(e)33 else:34 assert False, 'Expected a type error because of an invalid option.'353637def test_counting(runner):38 @click.command()39 @click.option('-v', count=True, help='Verbosity',40 type=click.IntRange(0, 3))
176 unmodified lines
modified:CHANGES+4 added
15 unmodified lines
16 override the autodetection.17- the CLI runner's result object now has a traceback attached.18- improved automatic short help detection to work better with19 dots that do not terminate sentences.20- when definining options without actual valid option strings21 now, Click will give an error message instead of silently22 passing. This should catch situations where users wanted to23 created arguments instead of options.2425Version 2.226-----------27
78 unmodified lines