@@ -342,12 +342,13 @@ def error(self, msg: str) -> None:
342
342
def _process_long_opt (self , rargs , values ) -> None :
343
343
"""SCons-specific processing of long options.
344
344
345
- This is copied directly from the normal
346
- ``optparse._process_long_opt()`` method, except that, if configured
347
- to do so, we catch the exception thrown when an unknown option
348
- is encountered and just stick it back on the "leftover" arguments
349
- for later (re-)processing. This is because we may see the option
350
- definition later, while processing SConscript files.
345
+ This is copied directly from the normal Optparse
346
+ :meth:`~optparse.OptionParser._process_long_opt` method, except
347
+ that, if configured to do so, we catch the exception thrown
348
+ when an unknown option is encountered and just stick it back
349
+ on the "leftover" arguments for later (re-)processing. This is
350
+ because we may see the option definition later, while processing
351
+ SConscript files.
351
352
"""
352
353
arg = rargs .pop (0 )
353
354
@@ -414,6 +415,66 @@ def _process_long_opt(self, rargs, values) -> None:
414
415
415
416
option .process (opt , value , values , self )
416
417
418
+
419
+ def _process_short_opts (self , rargs , values ) -> None :
420
+ """SCons-specific processing of short options.
421
+
422
+ This is copied directly from the normal Optparse
423
+ :meth:`~optparse.OptionParser._process_short_opts` method, except
424
+ that, if configured to do so, we catch the exception thrown
425
+ when an unknown option is encountered and just stick it back
426
+ on the "leftover" arguments for later (re-)processing. This is
427
+ because we may see the option definition later, while processing
428
+ SConscript files.
429
+ """
430
+ arg = rargs .pop (0 )
431
+ stop = False
432
+ i = 1
433
+ for ch in arg [1 :]:
434
+ opt = "-" + ch
435
+ option = self ._short_opt .get (opt )
436
+ i += 1 # we have consumed a character
437
+
438
+ try :
439
+ if not option :
440
+ raise optparse .BadOptionError (opt )
441
+ except optparse .BadOptionError :
442
+ # SCons addition: if requested, add unknown options to
443
+ # the "leftover arguments" list for later processing.
444
+ if self .preserve_unknown_options :
445
+ self .largs .append (arg )
446
+ return
447
+ raise
448
+
449
+ if option .takes_value ():
450
+ # Any characters left in arg? Pretend they're the
451
+ # next arg, and stop consuming characters of arg.
452
+ if i < len (arg ):
453
+ rargs .insert (0 , arg [i :])
454
+ stop = True
455
+
456
+ nargs = option .nargs
457
+ if len (rargs ) < nargs :
458
+ if nargs == 1 :
459
+ self .error (_ ("%s option requires an argument" ) % opt )
460
+ else :
461
+ self .error (_ ("%s option requires %d arguments" )
462
+ % (opt , nargs ))
463
+ elif nargs == 1 :
464
+ value = rargs .pop (0 )
465
+ else :
466
+ value = tuple (rargs [0 :nargs ])
467
+ del rargs [0 :nargs ]
468
+
469
+ else : # option doesn't take a value
470
+ value = None
471
+
472
+ option .process (opt , value , values , self )
473
+
474
+ if stop :
475
+ break
476
+
477
+
417
478
def reparse_local_options (self ) -> None :
418
479
"""Re-parse the leftover command-line options.
419
480
0 commit comments