mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +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
|
return True, opt
|
||||||
elif opt + '=?' in possibilities:
|
elif opt + '=?' in possibilities:
|
||||||
return '?', opt
|
return '?', opt
|
||||||
# No exact match, so better be unique.
|
# Possibilities must be unique to be accepted
|
||||||
if len(possibilities) > 1:
|
if len(possibilities) > 1:
|
||||||
# XXX since possibilities contains all valid continuations, might be
|
raise GetoptError(
|
||||||
# nice to work them into the error msg
|
_("option --%s not a unique prefix; possible options: %s")
|
||||||
raise GetoptError(_('option --%s not a unique prefix') % opt, opt)
|
% (opt, ", ".join(possibilities)),
|
||||||
|
opt,
|
||||||
|
)
|
||||||
assert len(possibilities) == 1
|
assert len(possibilities) == 1
|
||||||
unique_match = possibilities[0]
|
unique_match = possibilities[0]
|
||||||
if unique_match.endswith('=?'):
|
if unique_match.endswith('=?'):
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
option -%s not recognized
|
option -%s not recognized
|
||||||
option -%s requires argument
|
option -%s requires argument
|
||||||
option --%s must not have an 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 not recognized
|
||||||
option --%s requires argument
|
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