@@ -291,11 +291,14 @@ def _process_short_opts(self, rargs, values):
291291 raise
292292
293293 if option .takes_value ():
294+ had_explicit_value = False
295+
294296 # Any characters left in arg? Pretend they're the
295297 # next arg, and stop consuming characters of arg.
296298 if i < len (arg ):
297299 rargs .insert (0 , arg [i :])
298300 stop = True
301+ had_explicit_value = True
299302
300303 nargs = option .nargs
301304 if len (rargs ) < nargs :
@@ -306,9 +309,19 @@ def _process_short_opts(self, rargs, values):
306309 % (opt , nargs ))
307310 elif nargs == 1 :
308311 value = rargs .pop (0 )
312+ if not had_explicit_value :
313+ SCons .Script ._Remove_Target (value )
314+ if '=' in value :
315+ SCons .Script ._Remove_Argument (value )
309316 else :
310317 value = tuple (rargs [0 :nargs ])
311318 del rargs [0 :nargs ]
319+ for i in range (len (value )):
320+ if not had_explicit_value or i > 0 :
321+ SCons .Script ._Remove_Target (value [i ])
322+ if '=' in value [i ]:
323+ SCons .Script ._Remove_Argument (value [i ])
324+
312325
313326 else : # option doesn't take a value
314327 value = None
@@ -379,9 +392,18 @@ def _process_long_opt(self, rargs, values):
379392 % (opt , nargs ))
380393 elif nargs == 1 :
381394 value = rargs .pop (0 )
395+ if not had_explicit_value :
396+ SCons .Script ._Remove_Target (value )
397+ if '=' in value :
398+ SCons .Script ._Remove_Argument (value )
382399 else :
383400 value = tuple (rargs [0 :nargs ])
384401 del rargs [0 :nargs ]
402+ for i in range (len (value )):
403+ if not had_explicit_value or i > 0 :
404+ SCons .Script ._Remove_Target (value [i ])
405+ if '=' in value [i ]:
406+ SCons .Script ._Remove_Argument (value [i ])
385407
386408 elif had_explicit_value :
387409 self .error (_ ("%s option does not take a value" ) % opt )
@@ -391,69 +413,6 @@ def _process_long_opt(self, rargs, values):
391413
392414 option .process (opt , value , values , self )
393415
394- def reparse_local_options (self ):
395- """ Re-parse the leftover command-line options.
396-
397- Parse options stored in `self.largs`, so that any value
398- overridden on the command line is immediately available
399- if the user turns around and does a :func:`GetOption` right away.
400-
401- We mimic the processing of the single args
402- in the original OptionParser :func:`_process_args`, but here we
403- allow exact matches for long-opts only (no partial argument names!).
404- Otherwise there could be problems in :func:`add_local_option`
405- below. When called from there, we try to reparse the
406- command-line arguments that
407-
408- 1. haven't been processed so far (`self.largs`), but
409- 2. are possibly not added to the list of options yet.
410-
411- So, when we only have a value for "--myargument" so far,
412- a command-line argument of "--myarg=test" would set it,
413- per the behaviour of :func:`_match_long_opt`,
414- which allows for partial matches of the option name,
415- as long as the common prefix appears to be unique.
416- This would lead to further confusion, because we might want
417- to add another option "--myarg" later on (see issue #2929).
418-
419- """
420- rargs = []
421- largs_restore = []
422- # Loop over all remaining arguments
423- skip = False
424- for l in self .largs :
425- if skip :
426- # Accept all remaining arguments as they are
427- largs_restore .append (l )
428- else :
429- if len (l ) > 2 and l [0 :2 ] == "--" :
430- # Check long option
431- lopt = (l ,)
432- if "=" in l :
433- # Split into option and value
434- lopt = l .split ("=" , 1 )
435-
436- if lopt [0 ] in self ._long_opt :
437- # Argument is already known
438- rargs .append ('=' .join (lopt ))
439- else :
440- # Not known yet, so reject for now
441- largs_restore .append ('=' .join (lopt ))
442- else :
443- if l == "--" or l == "-" :
444- # Stop normal processing and don't
445- # process the rest of the command-line opts
446- largs_restore .append (l )
447- skip = True
448- else :
449- rargs .append (l )
450-
451- # Parse the filtered list
452- self .parse_args (rargs , self .values )
453- # Restore the list of remaining arguments for the
454- # next call of AddOption/add_local_option...
455- self .largs = self .largs + largs_restore
456-
457416 def add_local_option (self , * args , ** kw ):
458417 """
459418 Adds a local option to the parser.
@@ -481,8 +440,8 @@ def add_local_option(self, *args, **kw):
481440 # available if the user turns around and does a GetOption()
482441 # right away.
483442 setattr (self .values .__defaults__ , result .dest , result .default )
484- self .reparse_local_options ( )
485-
443+ self .parse_args ( self . largs , self . values )
444+
486445 return result
487446
488447class SConsIndentedHelpFormatter (optparse .IndentedHelpFormatter ):
0 commit comments