The most likely alternative is getopt.getopt, which doesn't rearrange
arguments. That would mean "-a foo -p" is considered as the option "-a"
followed by the non-option arguments ['foo', '-p'].
The non-gnu behaviour is annoying most of the time, but can be useful when
you're receiving command lines that you want to pass verbatim to someone
else.
class Options:
- def __init__(self, exe, optspec):
+ def __init__(self, exe, optspec, optfunc=getopt.gnu_getopt):
self.exe = exe
self.optspec = optspec
+ self.optfunc = optfunc
self._aliases = {}
self._shortopts = 'h?'
self._longopts = ['help']
def parse(self, args):
try:
- (flags,extra) = getopt.gnu_getopt(args,
- self._shortopts, self._longopts)
+ (flags,extra) = self.optfunc(args, self._shortopts, self._longopts)
except getopt.GetoptError, e:
self.fatal(e)