mirror of
https://github.com/python/cpython.git
synced 2025-07-07 11:25:30 +00:00
gh-126946: Improve error message in getopt.do_longs based on existing comment (GH-126871)
Include a list of possibilities for not unique prefix.
This commit is contained in:
parent
733fe59206
commit
f46d847574
3 changed files with 10 additions and 5 deletions
|
@ -185,11 +185,13 @@ def long_has_args(opt, longopts):
|
|||
return True, opt
|
||||
elif opt + '=?' in possibilities:
|
||||
return '?', opt
|
||||
# No exact match, so better be unique.
|
||||
# Possibilities must be unique to be accepted
|
||||
if len(possibilities) > 1:
|
||||
# XXX since possibilities contains all valid continuations, might be
|
||||
# nice to work them into the error msg
|
||||
raise GetoptError(_('option --%s not a unique prefix') % opt, opt)
|
||||
raise GetoptError(
|
||||
_("option --%s not a unique prefix; possible options: %s")
|
||||
% (opt, ", ".join(possibilities)),
|
||||
opt,
|
||||
)
|
||||
assert len(possibilities) == 1
|
||||
unique_match = possibilities[0]
|
||||
if unique_match.endswith('=?'):
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
option -%s not recognized
|
||||
option -%s requires argument
|
||||
option --%s must not have an argument
|
||||
option --%s not a unique prefix
|
||||
option --%s not a unique prefix; possible options: %s
|
||||
option --%s not recognized
|
||||
option --%s requires argument
|
|
@ -0,0 +1,3 @@
|
|||
Improve the :exc:`~getopt.GetoptError` error message when a long option
|
||||
prefix matches multiple accepted options in :func:`getopt.getopt` and
|
||||
:func:`getopt.gnu_getopt`.
|
Loading…
Add table
Add a link
Reference in a new issue