Skip to content

fix: show full option name in error for invalid multi-char short options#3207

Closed
by22Jy wants to merge 1 commit intopallets:mainfrom
by22Jy:fix-multichar-short-option-error-msg
Closed

fix: show full option name in error for invalid multi-char short options#3207
by22Jy wants to merge 1 commit intopallets:mainfrom
by22Jy:fix-multichar-short-option-error-msg

Conversation

@by22Jy
Copy link

@by22Jy by22Jy commented Feb 13, 2026

Summary

  • When a multi-character short option like -dbgwrong fails validation, the error message now shows the full option name instead of just the first character.

Context

Fixes #2779

Previously, when passing an invalid multi-character short option (e.g., -dbgwrong), the error would only show the first character:

No such option: -d

This was confusing because the user passed -dbgwrong, not -d.

Changes

Now the error correctly shows the full option name:

No such option: -dbgwrong

The fix captures the remaining characters when a short option fails to match and includes them in the error message.

Testing

Tested manually with a Click app:

import click

@click.command()
@click.option("-d", "--debug", is_flag=True)
def cli(debug):
    pass

if __name__ == "__main__":
    cli()

Running python test.py -dbgwrong now shows:

No such option: -dbgwrong

When a multi-character short option like `-dbgwrong` is passed and
fails validation, the error message now shows the full option name
instead of just the first character.

Before: No such option: -d
After: No such option: -dbgwrong

Fixes pallets#2779
@davidism davidism closed this Feb 13, 2026
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong error message when wrong multicharacter short option is passed

2 participants