Source code for hemlock.hemlock_options_parser
from optparse import (OptionParser,BadOptionError,AmbiguousOptionError)
# override OptionParser to ignore unknown arguments
# enables OptionParser to work without requiring Hemlock args to be processed by OptionParser
[docs]class PassThroughOptionParser(OptionParser):
"""
An unknown option pass-through implementation of OptionParser.
When unknown arguments are encountered, bundle with largs and try again,
until rargs is depleted.
sys.exit(status) will still be called if a known argument is passed
incorrectly (e.g. missing arguments or bad argument types, etc.)
"""
def _process_args(self, largs, rargs, values):
while rargs:
try:
OptionParser._process_args(self,largs,rargs,values)
except (BadOptionError,AmbiguousOptionError), e:
largs.append(e.opt_str)