summaryrefslogtreecommitdiffstats
path: root/SCons
diff options
context:
space:
mode:
authorWilliam Deegan <bill@baddogconsulting.com>2024-10-01 21:50:16 (GMT)
committerGitHub <noreply@github.com>2024-10-01 21:50:16 (GMT)
commitfc36781173e80c99774284c653557c6cb9675c88 (patch)
tree0c2b998506c1e84a2ca4d2b552a7ca9259aaae1d /SCons
parent4f3e3026bc455b3b47666567f273b2f84f932d32 (diff)
parentf0715f3f8853ff246140166b7cbc5c6793d3a590 (diff)
downloadSCons-fc36781173e80c99774284c653557c6cb9675c88.zip
SCons-fc36781173e80c99774284c653557c6cb9675c88.tar.gz
SCons-fc36781173e80c99774284c653557c6cb9675c88.tar.bz2
Merge pull request #4598 from mwichmann/AddOption-shortopts
Fix short-option processing
Diffstat (limited to 'SCons')
-rw-r--r--SCons/Script/SConsOptions.py73
1 files changed, 67 insertions, 6 deletions
diff --git a/SCons/Script/SConsOptions.py b/SCons/Script/SConsOptions.py
index c9c7aa0..0853181 100644
--- a/SCons/Script/SConsOptions.py
+++ b/SCons/Script/SConsOptions.py
@@ -342,12 +342,13 @@ class SConsOptionParser(optparse.OptionParser):
def _process_long_opt(self, rargs, values) -> None:
"""SCons-specific processing of long options.
- This is copied directly from the normal
- ``optparse._process_long_opt()`` method, except that, if configured
- to do so, we catch the exception thrown when an unknown option
- is encountered and just stick it back on the "leftover" arguments
- for later (re-)processing. This is because we may see the option
- definition later, while processing SConscript files.
+ This is copied directly from the normal Optparse
+ :meth:`~optparse.OptionParser._process_long_opt` method, except
+ that, if configured to do so, we catch the exception thrown
+ when an unknown option is encountered and just stick it back
+ on the "leftover" arguments for later (re-)processing. This is
+ because we may see the option definition later, while processing
+ SConscript files.
"""
arg = rargs.pop(0)
@@ -414,6 +415,66 @@ class SConsOptionParser(optparse.OptionParser):
option.process(opt, value, values, self)
+
+ def _process_short_opts(self, rargs, values) -> None:
+ """SCons-specific processing of short options.
+
+ This is copied directly from the normal Optparse
+ :meth:`~optparse.OptionParser._process_short_opts` method, except
+ that, if configured to do so, we catch the exception thrown
+ when an unknown option is encountered and just stick it back
+ on the "leftover" arguments for later (re-)processing. This is
+ because we may see the option definition later, while processing
+ SConscript files.
+ """
+ arg = rargs.pop(0)
+ stop = False
+ i = 1
+ for ch in arg[1:]:
+ opt = "-" + ch
+ option = self._short_opt.get(opt)
+ i += 1 # we have consumed a character
+
+ try:
+ if not option:
+ raise optparse.BadOptionError(opt)
+ except optparse.BadOptionError:
+ # SCons addition: if requested, add unknown options to
+ # the "leftover arguments" list for later processing.
+ if self.preserve_unknown_options:
+ self.largs.append(arg)
+ return
+ raise
+
+ if option.takes_value():
+ # Any characters left in arg? Pretend they're the
+ # next arg, and stop consuming characters of arg.
+ if i < len(arg):
+ rargs.insert(0, arg[i:])
+ stop = True
+
+ nargs = option.nargs
+ if len(rargs) < nargs:
+ if nargs == 1:
+ self.error(_("%s option requires an argument") % opt)
+ else:
+ self.error(_("%s option requires %d arguments")
+ % (opt, nargs))
+ elif nargs == 1:
+ value = rargs.pop(0)
+ else:
+ value = tuple(rargs[0:nargs])
+ del rargs[0:nargs]
+
+ else: # option doesn't take a value
+ value = None
+
+ option.process(opt, value, values, self)
+
+ if stop:
+ break
+
+
def reparse_local_options(self) -> None:
"""Re-parse the leftover command-line options.