Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/click/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def _match_short_opt(self, arg: str, state: _ParsingState) -> None:
if self.ignore_unknown_options:
unknown_options.append(ch)
continue
raise NoSuchOption(opt, ctx=self.ctx)
raise NoSuchOption(arg, ctx=self.ctx)
if option.takes_value:
# Any characters left in arg? Pretend they're the
# next arg, and stop consuming characters of arg.
Expand Down
13 changes: 13 additions & 0 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@ def cli():
assert f"No such option '{unknown_flag}'." in result.output


def test_unknown_multichar_short_option_shows_full_name(runner):
"""Error message should show the full option string, not just the first char."""

@click.command()
def cli():
pass

result = runner.invoke(cli, ["-dbg"])
assert result.exception
assert "No such option '-dbg'." in result.output
assert "No such option '-d'." not in result.output


@pytest.mark.parametrize(
("value", "expect"),
[
Expand Down