Lines 229-234
def get_comp_words():
Link Here
|
229 |
cwords.append(os.environ[cw]) |
229 |
cwords.append(os.environ[cw]) |
230 |
return cwords |
230 |
return cwords |
231 |
|
231 |
|
|
|
232 |
def determine_option_completer(option, completer, optarg): |
233 |
if option.nargs > 0: |
234 |
optarg = True |
235 |
if hasattr(option, 'completer'): |
236 |
completer = option.completer |
237 |
else: |
238 |
completer = opt_completer |
239 |
# Warn user at least, it could help him figure out the problem. |
240 |
elif hasattr(option, 'completer'): |
241 |
raise SystemExit("Error: optparse option with a completer " |
242 |
"does not take arguments: %s" % str(option)) |
243 |
return (completer, optarg) |
244 |
|
232 |
#------------------------------------------------------------------------------- |
245 |
#------------------------------------------------------------------------------- |
233 |
# |
246 |
# |
234 |
def autocomplete( parser, |
247 |
def autocomplete( parser, |
Lines 340-356
def autocomplete( parser,
Link Here
|
340 |
# The following line change solves the issue when trying to |
353 |
# The following line change solves the issue when trying to |
341 |
# complete more options after one that doesn't take any args. |
354 |
# complete more options after one that doesn't take any args. |
342 |
if option and option.nargs != None: |
355 |
if option and option.nargs != None: |
343 |
if option.nargs > 0: |
356 |
(completer, optarg) = determine_option_completer( |
344 |
optarg = True |
357 |
option, completer, optarg) |
345 |
if hasattr(option, 'completer'): |
358 |
|
346 |
completer = option.completer |
359 |
# Prev starts with '-' but no corresponding option could be |
347 |
else: |
360 |
# identified. This is likely due to squashed short opts as in -a -b |
348 |
completer = opt_completer |
361 |
# -c -> -abc. Loop through individual short opts to see if more than |
349 |
# Warn user at least, it could help him figure out the problem. |
362 |
# one of them takes arguments, in which case we don't try to |
350 |
elif hasattr(option, 'completer'): |
363 |
# complete since it's not unambiguous which option completer to use. |
351 |
raise SystemExit( |
364 |
elif not option and not prev.startswith('--'): |
352 |
"Error: optparse option with a completer " |
365 |
|
353 |
"does not take arguments: %s" % str(option)) |
366 |
n = 0 |
|
|
367 |
for so in tuple(prev.replace('-','')): |
368 |
short_option = parser.get_option("-%s" % so) |
369 |
|
370 |
if short_option: |
371 |
if short_option.nargs == None or \ |
372 |
short_option.nargs == 0: |
373 |
continue |
374 |
else: |
375 |
(completer, optarg) = determine_option_completer( |
376 |
short_option, completer, optarg) |
377 |
n += 1 |
378 |
|
379 |
if n > 1: |
380 |
sys.exit(exit_code) |
381 |
|
354 |
except KeyError: |
382 |
except KeyError: |
355 |
pass |
383 |
pass |
356 |
|
384 |
|