From: Avery Pennarun Date: Wed, 8 Sep 2010 07:37:44 +0000 (-0700) Subject: options.py: handle optspecs that include inline square brackets. X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=ef0bbbb266c2f6f058065556b01e3ccb53c8dd44;p=packages%2Fb%2Fbup.git options.py: handle optspecs that include inline square brackets. 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 --- diff --git a/lib/bup/options.py b/lib/bup/options.py index 0529f59..662ade4 100644 --- a/lib/bup/options.py +++ b/lib/bup/options.py @@ -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: diff --git a/lib/bup/t/toptions.py b/lib/bup/t/toptions.py index d7077f6..02d9839 100644 --- a/lib/bup/t/toptions.py +++ b/lib/bup/t/toptions.py @@ -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))