Explorar el Código

be more helpful when parsing invalid --pattern values

say what the real problem is.
say what is valid.

(cherry picked from commit f5ba0fc6498babb7a7b26ccd4c19e4169dfb5d8e)
Thomas Waldmann hace 7 años
padre
commit
1e7c87b23d
Se han modificado 1 ficheros con 12 adiciones y 11 borrados
  1. 12 11
      src/borg/patterns.py

+ 12 - 11
src/borg/patterns.py

@@ -367,17 +367,18 @@ def parse_inclexcl_command(cmd_line_str, fallback=ShellPattern):
         'P': IECommand.PatternStyle,
         'p': IECommand.PatternStyle,
     }
-
-    try:
-        cmd = cmd_prefix_map[cmd_line_str[0]]
-
-        # remaining text on command-line following the command character
-        remainder_str = cmd_line_str[1:].lstrip()
-
-        if not remainder_str:
-            raise ValueError("Missing pattern/information!")
-    except (IndexError, KeyError, ValueError):
-        raise argparse.ArgumentTypeError("Unable to parse pattern/command: {}".format(cmd_line_str))
+    if not cmd_line_str:
+        raise argparse.ArgumentTypeError("A pattern/command must not be empty.")
+
+    cmd = cmd_prefix_map.get(cmd_line_str[0])
+    if cmd is None:
+        raise argparse.ArgumentTypeError("A pattern/command must start with any one of: %s" %
+                                         ', '.join(cmd_prefix_map))
+
+    # remaining text on command-line following the command character
+    remainder_str = cmd_line_str[1:].lstrip()
+    if not remainder_str:
+        raise argparse.ArgumentTypeError("A pattern/command must have a value part.")
 
     if cmd is IECommand.RootPath:
         # TODO: validate string?