From: Avery Pennarun Date: Sun, 21 Mar 2010 04:36:31 +0000 (-0400) Subject: options: allow user to specify an alternative to getopt.gnu_getopt. X-Git-Tag: bup-0.13~3 X-Git-Url: https://arthur.barton.de/gitweb/?a=commitdiff_plain;h=f168a50f607750ff60cbe90a908dd1e4a6834d89;p=bup.git options: allow user to specify an alternative to getopt.gnu_getopt. 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. --- diff --git a/lib/bup/options.py b/lib/bup/options.py index caa6a65..b40d6b4 100644 --- a/lib/bup/options.py +++ b/lib/bup/options.py @@ -15,9 +15,10 @@ class OptDict: 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'] @@ -84,8 +85,7 @@ class Options: 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)