From 9b64eb3d2887aac45f0106deb5053f0f085fce4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=85=B4=E9=9A=86?= <81056572+717986230@users.noreply.github.com> Date: Fri, 3 Apr 2026 19:34:06 +0800 Subject: [PATCH 1/2] Fix #2779: Show full option name in error for multicharacter short options When passing a wrong multicharacter short option like `-dbgwrong`, the error message incorrectly shows 'No such option: -d' instead of the full option name. This fix reports the full original argument when raising NoSuchOption, instead of just the first invalid character. Fixes #2779 --- src/click/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/click/parser.py b/src/click/parser.py index 1ea1f7166e..44aedadad7 100644 --- a/src/click/parser.py +++ b/src/click/parser.py @@ -401,7 +401,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(_normalize_opt(arg, self.ctx), ctx=self.ctx) # Fix #2779 if option.takes_value: # Any characters left in arg? Pretend they're the # next arg, and stop consuming characters of arg. From 40fab56cf6603164538889a82c508c66cbc45dca Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Fri, 3 Apr 2026 11:36:39 +0000 Subject: [PATCH 2/2] [pre-commit.ci lite] apply automatic fixes --- src/click/parser.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/click/parser.py b/src/click/parser.py index 44aedadad7..713c4a2c77 100644 --- a/src/click/parser.py +++ b/src/click/parser.py @@ -401,7 +401,9 @@ def _match_short_opt(self, arg: str, state: _ParsingState) -> None: if self.ignore_unknown_options: unknown_options.append(ch) continue - raise NoSuchOption(_normalize_opt(arg, self.ctx), ctx=self.ctx) # Fix #2779 + raise NoSuchOption( + _normalize_opt(arg, self.ctx), ctx=self.ctx + ) # Fix #2779 if option.takes_value: # Any characters left in arg? Pretend they're the # next arg, and stop consuming characters of arg.