option.process(opt, value, values, self)
+ def reparse_local_options(self):
+ Re-parse the leftover command-line options stored
+ in self.largs, so that any value overridden on the
+ command line is immediately available if the user turns
+ around and does a GetOption() right away.
+ We mimic the processing of the single args
+ in the original OptionParser._process_args(), but here we
+ allow exact matches for long-opts only (no partial
+ Else, this would lead to problems in add_local_option()
+ below. When called from there, we try to reparse the
+ command-line arguments that
+ 1. haven't been processed so far (self.largs), but
+ 2. are possibly not added to the list of options yet.
+ So, when we only have a value for "--myargument" yet,
+ a command-line argument of "--myarg=test" would set it.
+ Responsible for this behaviour is the method
+ _match_long_opt(), which allows for partial matches of
+ the option name, as long as the common prefix appears to
+ This would lead to further confusion, because we might want
+ to add another option "--myarg" later on (see issue #2929).
+ # Loop over all remaining arguments
+ # Accept all remaining arguments as they are
+ if len(l) > 2 and l[0:2] == "--":
+ # Split into option and value
+ if lopt in self._long_opt:
+ # Argument is already known
+ # Not known yet, so reject for now
+ if l == "--" or l == "-":
+ # Stop normal processing and don't
+ # process the rest of the command-line opts
+ # Parse the filtered list
+ self.parse_args(rargs, self.values)
+ # Restore the list of remaining arguments for the
+ # next call of AddOption/add_local_option...
+ self.largs = self.largs + largs_restore
def add_local_option(self, *args, **kw):
Adds a local option to the parser.
# available if the user turns around and does a GetOption()
setattr(self.values.__defaults__, result.dest, result.default)