diff --git a/NEWS b/NEWS index 586fe1de..41ee5fef 100644 --- a/NEWS +++ b/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. diff --git a/borgmatic/commands/arguments.py b/borgmatic/commands/arguments.py index 6b857f2c..7e054f5a 100644 --- a/borgmatic/commands/arguments.py +++ b/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, diff --git a/setup.py b/setup.py index 65db6fc2..37ff017a 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.7.15' +VERSION = '1.7.16.dev0' setup( diff --git a/tests/integration/commands/test_arguments.py b/tests/integration/commands/test_arguments.py index f992f9aa..27dc3234 100644 --- a/tests/integration/commands/test_arguments.py +++ b/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)