getopt used to sort the long option names, in an attempt to simplify
the logic. That resulted in a bug. My previous getopt checkin repaired the bug but left the sorting. The solution is significantly simpler if we don't bother sorting at all, so this checkin gets rid of the sort and the code that relied on it.
This commit is contained in:
parent
36cdad12dd
commit
d31b6328e1
|
@ -65,7 +65,6 @@ def getopt(args, shortopts, longopts = []):
|
||||||
longopts = [longopts]
|
longopts = [longopts]
|
||||||
else:
|
else:
|
||||||
longopts = list(longopts)
|
longopts = list(longopts)
|
||||||
longopts.sort()
|
|
||||||
while args and args[0].startswith('-') and args[0] != '-':
|
while args and args[0].startswith('-') and args[0] != '-':
|
||||||
if args[0] == '--':
|
if args[0] == '--':
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
|
@ -99,19 +98,10 @@ def do_longs(opts, opt, longopts, args):
|
||||||
# Return:
|
# Return:
|
||||||
# has_arg?
|
# has_arg?
|
||||||
# full option name
|
# full option name
|
||||||
# Assumes longopts has been sorted (ASCII order).
|
|
||||||
def long_has_args(opt, longopts):
|
def long_has_args(opt, longopts):
|
||||||
for i in range(len(longopts)):
|
possibilities = [o for o in longopts if o.startswith(opt)]
|
||||||
if longopts[i].startswith(opt):
|
if not possibilities:
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise GetoptError('option --%s not recognized' % opt, opt)
|
raise GetoptError('option --%s not recognized' % opt, opt)
|
||||||
# opt is a prefix of longopts[i]; find j s.t. opt is a prefix of
|
|
||||||
# each possibility in longopts[i:j]
|
|
||||||
j = i+1
|
|
||||||
while j < len(longopts) and longopts[j].startswith(opt):
|
|
||||||
j += 1
|
|
||||||
possibilities = longopts[i:j]
|
|
||||||
# Is there an exact match?
|
# Is there an exact match?
|
||||||
if opt in possibilities:
|
if opt in possibilities:
|
||||||
return 0, opt
|
return 0, opt
|
||||||
|
|
Loading…
Reference in New Issue