@@ -359,43 +359,60 @@ def reparse_local_options(self):
359
359
This would lead to further confusion, because we might want
360
360
to add another option "--myarg" later on (see issue #2929).
361
361
362
+ The implementation proved to be problematic in the case of
363
+ space-separation (--arg opt) style, where the arg gets
364
+ separated from the opt. So now we try to figure out if there
365
+ are nargs and pop them off largs.
362
366
"""
363
367
rargs = []
364
- largs_restore = []
368
+ largs = []
365
369
# Loop over all remaining arguments
366
370
skip = False
367
- for l in self .largs :
371
+
372
+ for idx , larg in enumerate (self .largs ):
368
373
if skip :
369
374
# Accept all remaining arguments as they are
370
- largs_restore .append (l )
375
+ largs .append (larg )
371
376
else :
372
- if len (l ) > 2 and l [0 :2 ] == "--" :
377
+ if len (larg ) > 2 and larg [0 :2 ] == "--" :
373
378
# Check long option
374
- lopt = (l ,)
375
- if "=" in l :
379
+ if "=" in larg :
376
380
# Split into option and value
377
- lopt = l .split ("=" , 1 )
381
+ lopt = larg .split ("=" , 1 )
382
+ else :
383
+ lopt = [larg ]
378
384
379
385
if lopt [0 ] in self ._long_opt :
380
386
# Argument is already known
381
- rargs .append ('=' .join (lopt ))
387
+ if len (lopt ) > 1 :
388
+ # "--opt=arg" style, join it back up
389
+ rargs .append ('=' .join (lopt ))
390
+ else :
391
+ rargs .append (larg )
392
+ # maybe "--opt arg" style, pull matching args
393
+ option = self ._long_opt [larg ]
394
+ if option .takes_value ():
395
+ for _ in range (option .nargs ):
396
+ try :
397
+ rargs .append (self .largs .pop (idx + 1 ))
398
+ except IndexError :
399
+ # missing args, will be handled later
400
+ pass
382
401
else :
383
402
# Not known yet, so reject for now
384
- largs_restore .append ('=' .join (lopt ))
403
+ largs .append ('=' .join (lopt ))
385
404
else :
386
- if l == "--" or l == "-" :
405
+ if larg in ( "--" , "-" ) :
387
406
# Stop normal processing and don't
388
407
# process the rest of the command-line opts
389
- largs_restore .append (l )
390
408
skip = True
391
- else :
392
- rargs .append (l )
409
+ largs .append (larg )
393
410
394
411
# Parse the filtered list
395
412
self .parse_args (rargs , self .values )
396
413
# Restore the list of remaining arguments for the
397
414
# next call of AddOption/add_local_option...
398
- self .largs = self . largs + largs_restore
415
+ self .largs = largs
399
416
400
417
def add_local_option (self , * args , ** kw ):
401
418
"""
0 commit comments