diff --git a/src/click/parser.py b/src/click/parser.py index 4fcbf7caa..bf86af1f5 100644 --- a/src/click/parser.py +++ b/src/click/parser.py @@ -402,6 +402,17 @@ def _match_short_opt(self, arg: str, state: _ParsingState) -> None: if self.ignore_unknown_options: unknown_options.append(ch) continue + # If the very first character of the short-option group is + # not a registered option, the user most likely intended the + # entire token as a single option name (e.g. -dbgwrong). + # Raise with the full original argument so the error message + # is more helpful. If a later character fails, we keep the + # per-character diagnostic (e.g. -abZ where -a and -b are + # valid but -Z is not). + if i == 2: + raise NoSuchOption( + arg, possibilities=self._long_opt, ctx=self.ctx + ) raise NoSuchOption(opt, ctx=self.ctx) if option.takes_value: # Any characters left in arg? Pretend they're the