Skip to content
Myr

Bug fix #793; use the first defined long name

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 2ab5f7e · Browse files · 3 files+25 added−2 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+25 added−2 removed

  • tests:+22 added−0 removed
  • other:+3 added−2 removed

3 files+25 added−2 removed

modified:click/core.py+2 added-2 removed
1546 unmodified lines
1547 possible_names.append(split_opt(decl))1548 opts.append(decl)15491550 if name is None and possible_names:1551 possible_names.sort(key=lambda x: len(x[0]))1552 name = possible_names[-1][1].replace('-', '_').lower()1551 possible_names.sort(key=lambda x: -len(x[0])) # group long options first1552 name = possible_names[0][1].replace('-', '_').lower()1553 if not isidentifier(name):1554 name = None15551556 if name is None:
188 unmodified lines
modified:tests/test_options.py+22 added
333 unmodified lines
334 result = runner.invoke(cli_alt, ['--no-warnings'])335 assert result.output == 'False\n'336 result = runner.invoke(cli_alt, ['-w'])337 assert result.output == 'True\n'338339@pytest.mark.parametrize('option_args,expected', [340 (['--aggressive', '--all', '-a'], 'aggressive'),341 (['--first', '--second', '--third', '-a', '-b', '-c'], 'first'),342 (['--apple', '--banana', '--cantaloupe', '-a', '-b', '-c'], 'apple'),343 (['--cantaloupe', '--banana', '--apple', '-c', '-b', '-a'], 'cantaloupe'),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])349def test_multiple_long_options(runner, option_args, expected):350 @click.command()351 @click.option(*option_args, is_flag=True)352 def cmd(**kwargs):353 click.echo(str(kwargs[expected]))354355 assert cmd.params[0].name == expected356357 for form in option_args:358 result = runner.invoke(cmd, [form])359 assert result.output == 'True\n'
modified:CHANGES+1 added
11 unmodified lines
12 #728.13- Fix bug in test runner when calling ``sys.exit`` with ``None``. See #739.14- Fix crash on Windows console, see #744.15- Fix bashcompletion on chained commands. See #754.16- Fix option naming routine to match documentation. See #7931718Version 6.719-----------20
343 unmodified lines