Skip to content
Myr

Merge pull request #1355 from jtrakk/patch-1

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

suggest renaming option from 'name' to '--name'

authored by David Lord · committed by GitHub · parents ca75bab, e389b5e · Browse files · 3 files+10 added−7 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+10 added−7 removed

  • tests:+6 added−5 removed
  • other:+4 added−2 removed

3 files+10 added−7 removed

modified:src/click/core.py+2 added-2 removed
1975 unmodified lines
19761977 if not opts and not secondary_opts:1978 raise TypeError(1979 f"No options defined but a name was passed ({name})."1980 " Did you mean to declare an argument instead of an"1981 " option?"1980 " Did you mean to declare an argument instead? Did"1981 f" you mean to pass '--{name}'?"1982 )19831984 return name, opts, secondary_opts1985
221 unmodified lines
modified:tests/test_options.py+6 added-5 removed
21 unmodified lines
22 assert re.search(r"--bar\s+das bar", result.output) is not None232425def test_invalid_option(runner):26 with pytest.raises(TypeError, match="name was passed"):26 with pytest.raises(TypeError, match="name was passed") as exc_info:27 click.Option(["foo"])2828 @click.command()29 @click.option("foo")30 def cli(foo):31 pass29 message = str(exc_info.value)30 assert "name was passed (foo)" in message31 assert "declare an argument" in message32 assert "'--foo'" in message333435def test_invalid_nargs(runner):36 with pytest.raises(TypeError, match="nargs < 0"):
569 unmodified lines
modified:CHANGES.rst+2 added
71 unmodified lines
72 invoked command. :pr:`1312`73- Required arguments with the ``Choice`` type show the choices in74 curly braces to indicate that one is required (``{a|b|c}``).75 :issue:`1272`76- If only a name is passed to ``option()``, Click suggests renaming it77 to ``--name``. :pr:`1355`787980Version 7.1.281-------------
635 unmodified lines