]> git.michaelhowe.org Git - packages/b/bup.git/commitdiff
options.py: handle optspecs that include inline square brackets.
authorAvery Pennarun <apenwarr@gmail.com>
Wed, 8 Sep 2010 07:37:44 +0000 (00:37 -0700)
committerAvery Pennarun <apenwarr@gmail.com>
Wed, 8 Sep 2010 07:37:44 +0000 (00:37 -0700)
We recently made it so if the last thing on an options line was [defval],
then the value in brackets became the default for that option.  However, we
inadvertently matched *any* bracketed value on that line, not just the one
at the end of the line, which basically prevents us from using square
brackets anywhere on the line.  That's no fun.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
lib/bup/options.py
lib/bup/t/toptions.py

index 0529f5983c5b8fe11a00f3de559927712499e6f7..662ade43233fa51579117b1fea3259100ebb6c1f 100644 (file)
@@ -97,7 +97,7 @@ class Options:
                     has_parm = 1
                 else:
                     has_parm = 0
-                g = re.search(r'\[([^\]]*)\]', extra)
+                g = re.search(r'\[([^\]]*)\]$', extra)
                 if g:
                     defval = g.group(1)
                 else:
index d7077f6b5f41c315864f72e665833c207968e0b4..02d9839621d8d91261bd3ff9d9aee70c29c67e4b 100644 (file)
@@ -32,6 +32,11 @@ l,longoption=   long option with parameters and a really really long description
 p= short option with parameters
 onlylong  long option with no short
 neveropt never called options
+deftest1=  a default option with default [1]
+deftest2=  a default option with [1] default [2]
+deftest3=  a default option with [3] no actual default
+deftest4=  a default option with [[square]]
+deftest5=  a default option with "correct" [[square]
 no-stupid  disable stupidity
 """
 
@@ -49,6 +54,8 @@ def test_options():
     WVPASSEQ(extra, ['hanky'])
     WVPASSEQ((opt.t, opt.q, opt.p, opt.l, opt.onlylong,
               opt.neveropt), (3,1,7,19,1,None))
+    WVPASSEQ((opt.deftest1, opt.deftest2, opt.deftest3, opt.deftest4,
+              opt.deftest5), (1,2,None,None,'[square'))
     WVPASSEQ((opt.stupid, opt.no_stupid), (True, False))
     (opt,flags,extra) = o.parse(['--onlylong', '-t', '--no-onlylong'])
     WVPASSEQ((opt.t, opt.q, opt.onlylong), (1, None, 0))