]> arthur.barton.de Git - bup.git/commitdiff
bup.main: restore support for --x=y style arguments
authorRob Browning <rlb@defaultvalue.org>
Sat, 22 May 2021 17:25:01 +0000 (12:25 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sun, 30 May 2021 16:16:06 +0000 (11:16 -0500)
Previously removed in 3a01e9021f7e7c5eafec996f4fd5d5613bb776ce.

Reported-by: Mark J Hewitt <mjh@idnet.com>
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/main.py
test/ext/test-main

index 928f5a6b2962306eabb93be593a76d14c52cd928..70066bd144573e36de6bbcec77aac3ec4e7c76e5 100755 (executable)
@@ -107,6 +107,24 @@ def usage(msg=""):
         log("\n%s\n" % msg)
     sys.exit(99)
 
+def extract_argval(args):
+    """Assume args (all elements bytes) starts with a -x, --x, or --x=,
+argument that requires a value and return that value and the remaining
+args.  Exit with an errror if the value is missing.
+
+    """
+    # Assumes that first arg is a valid arg
+    arg = args[0]
+    if b'=' in arg:
+        val = arg.split(b'=')[1]
+        if not val:
+            usage('error: no value provided for %s option' % arg)
+        return val, args[1:]
+    if len(args) < 2:
+        usage('error: no value provided for %s option' % arg)
+    return args[1], args[2:]
+
+
 args = compat.get_argvb()
 if len(args) < 2:
     usage()
@@ -118,6 +136,7 @@ bup_dir = None
 args = args[1:]
 while args:
     arg = args[0]
+    print('arg:', arg, file=sys.stderr)
     if arg in (b'-?', b'--help'):
         help_requested = True
         args = args[1:]
@@ -131,13 +150,11 @@ while args:
     elif arg == b'--profile':
         do_profile = True
         args = args[1:]
-    elif arg in (b'-d', b'--bup-dir'):
-        if len(args) < 2:
-            usage('error: no path provided for %s option' % arg)
-        bup_dir = args[1]
-        args = args[2:]
-    elif arg == b'--import-py-module':
-        args = args[2:]
+    elif arg in (b'-d', b'--bup-dir') or arg.startswith(b'--bup-dir='):
+        bup_dir, args = extract_argval(args)
+    elif arg == b'--import-py-module' or arg.startswith(b'--import-py-module='):
+        # Just need to skip it here
+        _, args = extract_argval(args)
     elif arg.startswith(b'-'):
         usage('error: unexpected option "%s"'
               % arg.decode('ascii', 'backslashescape'))
index 60700ec7e30dac020120cba92f80becd11f191f3..e8e1d09024b055f6b52f22b89217be707adfbbe1 100755 (executable)
@@ -8,10 +8,9 @@ TOP="$(WVPASS pwd)" || exit $?
 tmpdir="$(WVPASS wvmktempdir)" || exit $?
 export BUP_DIR="$tmpdir/bup"
 
-bup()
-{
-    "$TOP/bup" "$@"
-}
+bup() { "$TOP/bup" "$@"; }
+
+WVPASS cd "$tmpdir"
 
 WVSTART 'main'
 
@@ -19,4 +18,7 @@ bup
 rc=$?
 WVPASSEQ "$rc" 99
 
+# Check --x=y handling
+WVPASS bup --bup-dir=repo init
+
 WVPASS rm -r "$tmpdir"