Browse Source

Fix regression of argument parsing for default actions (#220).

pull/226/head 1.3.18
Dan Helfman 2 years ago
parent
commit
340bd72176
  1. 3
      NEWS
  2. 10
      borgmatic/commands/arguments.py
  3. 2
      setup.py
  4. 12
      tests/integration/commands/test_arguments.py

3
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.

10
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:

2
setup.py

@ -1,6 +1,6 @@
from setuptools import find_packages, setup
VERSION = '1.3.17'
VERSION = '1.3.18'
setup(

12
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'])

Loading…
Cancel
Save