Skip to content
Myr

Merge pull request #1594 from MLH-Fellowship/duplicate-boolean-flags

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

raise ValueError for duplicate flags

authored by David Lord · committed by GitHub · parents e8de91d, 7de4708 · Browse files · 3 files+12 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+12 added−0 removed

  • tests:+5 added−0 removed
  • other:+7 added−0 removed

3 files+12 added−0 removed

modified:src/click/core.py+5 added
1838 unmodified lines
1839 opts.append(first)1840 second = second.lstrip()1841 if second:1842 secondary_opts.append(second.lstrip())1843 if first == second:1844 raise ValueError(1845 f"Boolean option {decl!r} cannot use the"1846 " same flag for true/false."1847 )1848 else:1849 possible_names.append(split_opt(decl))1850 opts.append(decl)1851
228 unmodified lines
modified:tests/test_options.py+5 added
563 unmodified lines
564 for form in option_args:565 if form.startswith("-"):566 result = runner.invoke(cmd, [form])567 assert result.output == "True\n"568569570def test_flag_duplicate_names(runner):571 with pytest.raises(ValueError, match="cannot use the same flag for true/false"):572 click.Option(["--foo/--foo"], default=False)
modified:CHANGES.rst+2 added
18 unmodified lines
19- If validation fails for a prompt with ``hide_input=True``, the value20 is not shown in the error message. :issue:`1460`21- An ``IntRange`` option shows the accepted range in its help text.22 :issue:`1525`23- An option defined with duplicate flag names (``"--foo/--foo"``)24 raises a ``ValueError``. :issue:`1465`252627Version 7.1.228-------------
635 unmodified lines