]> arthur.barton.de Git - bup.git/commitdiff
options: allow user to specify an alternative to getopt.gnu_getopt.
authorAvery Pennarun <apenwarr@gmail.com>
Sun, 21 Mar 2010 04:36:31 +0000 (00:36 -0400)
committerAvery Pennarun <apenwarr@gmail.com>
Sun, 21 Mar 2010 05:50:22 +0000 (01:50 -0400)
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.

lib/bup/options.py

index caa6a6545cf590e80704e263231b060b50bb976d..b40d6b4037c2b4b29b06f1df75abeb70cbc7cd2b 100644 (file)
@@ -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)