Преглед на файлове

Fix an error when running "borg key export" through borgmatic (#719).

Dan Helfman преди 1 година
родител
ревизия
b242078f54
променени са 4 файла, в които са добавени 24 реда и са изтрити 4 реда
  1. 3 0
      NEWS
  2. 9 3
      borgmatic/commands/arguments.py
  3. 1 1
      setup.py
  4. 11 0
      tests/integration/commands/test_arguments.py

+ 3 - 0
NEWS

@@ -1,3 +1,6 @@
+1.7.16.dev0
+ * #719: Fix an error when running "borg key export" through borgmatic.
+
 1.7.15
  * #326: Add configuration options and command-line flags for backing up a database from one
    location while restoring it somewhere else.

+ 9 - 3
borgmatic/commands/arguments.py

@@ -216,15 +216,21 @@ def parse_arguments_for_actions(unparsed_arguments, action_parsers, global_parse
     arguments['global'], remaining = global_parser.parse_known_args(unparsed_arguments)
     remaining_action_arguments.append(remaining)
 
-    # Prevent action names that follow "--config" paths from being considered as additional paths.
+    # Prevent action names and arguments that follow "--config" paths from being considered as
+    # additional paths.
     for argument_name in arguments.keys():
         if argument_name == 'global':
             continue
 
         for action_name in [argument_name] + ACTION_ALIASES.get(argument_name, []):
-            if action_name in arguments['global'].config_paths:
-                arguments['global'].config_paths.remove(action_name)
+            try:
+                action_name_index = arguments['global'].config_paths.index(action_name)
+                arguments['global'].config_paths = arguments['global'].config_paths[
+                    :action_name_index
+                ]
                 break
+            except ValueError:
+                pass
 
     return (
         arguments,

+ 1 - 1
setup.py

@@ -1,6 +1,6 @@
 from setuptools import find_packages, setup
 
-VERSION = '1.7.15'
+VERSION = '1.7.16.dev0'
 
 
 setup(

+ 11 - 0
tests/integration/commands/test_arguments.py

@@ -52,6 +52,17 @@ def test_parse_arguments_with_action_after_config_path_omits_aliased_action():
     assert arguments['rcreate'].encryption_mode == 'repokey'
 
 
+def test_parse_arguments_with_action_and_positional_arguments_after_config_path_omits_action_and_arguments():
+    flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
+
+    arguments = module.parse_arguments('--config', 'myconfig', 'borg', 'key', 'export')
+
+    global_arguments = arguments['global']
+    assert global_arguments.config_paths == ['myconfig']
+    assert 'borg' in arguments
+    assert arguments['borg'].options == ['key', 'export']
+
+
 def test_parse_arguments_with_verbosity_overrides_default():
     config_paths = ['default']
     flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths)