From 248f82d6f6ac48504447f5da9cc0f1643a6a7100 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Wed, 21 Jun 2023 10:41:32 -0700 Subject: [PATCH] Fix for another subaction argument-parsing edge case (#712). --- borgmatic/commands/arguments.py | 16 ++++++++++------ tests/integration/commands/test_arguments.py | 8 +++++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/borgmatic/commands/arguments.py b/borgmatic/commands/arguments.py index 2f978a3..02a0d11 100644 --- a/borgmatic/commands/arguments.py +++ b/borgmatic/commands/arguments.py @@ -161,17 +161,21 @@ def parse_arguments_for_actions(unparsed_arguments, action_parsers): subaction_parsers = get_subaction_parsers(action_parser) - # Parse with subaction parsers, if any. + # But first parse with subaction parsers, if any. if subaction_parsers: subactions_parsed = False for subaction_name, subaction_parser in subaction_parsers.items(): remaining_action_arguments.append( - parse_and_record_action_arguments( - unparsed_arguments, - arguments, - subaction_parser, - subaction_name, + tuple( + argument + for argument in parse_and_record_action_arguments( + unparsed_arguments, + arguments, + subaction_parser, + subaction_name, + ) + if argument != action_name ) ) diff --git a/tests/integration/commands/test_arguments.py b/tests/integration/commands/test_arguments.py index b2b0384..ea5891d 100644 --- a/tests/integration/commands/test_arguments.py +++ b/tests/integration/commands/test_arguments.py @@ -587,7 +587,13 @@ def test_parse_arguments_config_with_subaction_and_required_flags_does_not_raise module.parse_arguments('config', 'bootstrap', '--repository', 'repo.borg') -def test_parse_arguments_config_with_subaction_and_global_flags_does_not_raise(capsys): +def test_parse_arguments_config_with_subaction_and_global_flags_at_start_does_not_raise(capsys): flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) module.parse_arguments('--verbosity', '1', 'config', 'bootstrap', '--repository', 'repo.borg') + + +def test_parse_arguments_config_with_subaction_and_global_flags_at_end_does_not_raise(capsys): + flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) + + module.parse_arguments('config', 'bootstrap', '--repository', 'repo.borg', '--verbosity', '1')