From 340bd7217654186bd04a10b475925d99e6fda090 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sun, 22 Sep 2019 11:30:58 -0700 Subject: [PATCH] Fix regression of argument parsing for default actions (#220). --- NEWS | 3 +++ borgmatic/commands/arguments.py | 10 ++++++++++ setup.py | 2 +- tests/integration/commands/test_arguments.py | 12 ++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index c0680e4dc..7192591ba 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +1.3.18 + * #220: Fix regression of argument parsing for default actions. + 1.3.17 * #217: Fix error with "borgmatic check --only" command-line flag with "extract" consistency check. diff --git a/borgmatic/commands/arguments.py b/borgmatic/commands/arguments.py index 542a9f840..7eb55a2d6 100644 --- a/borgmatic/commands/arguments.py +++ b/borgmatic/commands/arguments.py @@ -80,6 +80,16 @@ def parse_global_arguments(unparsed_arguments, top_level_parser, subparsers): present_subparser_names.add(subparser_name) unused_parsed, remaining_arguments = subparser.parse_known_args(remaining_arguments) + # If no actions are explicitly requested, assume defaults: prune, create, and check. + if ( + not present_subparser_names + and '--help' not in unparsed_arguments + and '-h' not in unparsed_arguments + ): + for subparser_name in ('prune', 'create', 'check'): + subparser = subparsers.choices[subparser_name] + unused_parsed, remaining_arguments = subparser.parse_known_args(remaining_arguments) + # Remove the subparser names themselves. for subparser_name in present_subparser_names: if subparser_name in remaining_arguments: diff --git a/setup.py b/setup.py index 1987d92e7..20a99c8c4 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.3.17' +VERSION = '1.3.18' setup( diff --git a/tests/integration/commands/test_arguments.py b/tests/integration/commands/test_arguments.py index d6023c509..c13756c30 100644 --- a/tests/integration/commands/test_arguments.py +++ b/tests/integration/commands/test_arguments.py @@ -78,6 +78,18 @@ def test_parse_arguments_with_no_actions_defaults_to_all_actions_enabled(): assert 'check' in arguments +def test_parse_arguments_with_no_actions_passes_argument_to_relevant_actions(): + flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default']) + + arguments = module.parse_arguments('--stats') + + assert 'prune' in arguments + assert arguments['prune'].stats + assert 'create' in arguments + assert arguments['create'].stats + assert 'check' in arguments + + def test_parse_arguments_with_help_and_no_actions_shows_global_help(capsys): flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])