From 2dc006aab49961443fe8f9b341f98cd5f5fd8cc4 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sun, 27 Jan 2019 12:15:47 -0800 Subject: [PATCH] Allow use of --stats flag when --create or --prune flags are implied (#139). --- NEWS | 1 + borgmatic/commands/borgmatic.py | 22 +++++++++++++------- tests/integration/commands/test_borgmatic.py | 4 ++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 1c03e366e..77f827aa6 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ 1.2.15.dev0 * #136: Handle and format validation errors raised during argument parsing. + * #139: Allow use of --stats flag when --create or --prune flags are implied. 1.2.14 * #103: When generating sample configuration with generate-borgmatic-config, document the defaults diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 425215caf..01f15fed5 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -166,9 +166,6 @@ def parse_arguments(*arguments): if args.progress and not args.create: raise ValueError('The --progress option can only be used with the --create option') - if args.stats and not (args.create or args.prune): - raise ValueError('The --stats option can only be used with the --create or --prune options') - if args.json and not (args.create or args.list or args.info): raise ValueError( 'The --json option can only be used with the --create, --list, or --info options' @@ -181,12 +178,21 @@ def parse_arguments(*arguments): # If any of the action flags are explicitly requested, leave them as-is. Otherwise, assume # defaults: Mutate the given arguments to enable the default actions. - if args.init or args.prune or args.create or args.check or args.list or args.info: - return args + if ( + not args.init + and not args.prune + and not args.create + and not args.check + and not args.list + and not args.info + ): + args.prune = True + args.create = True + args.check = True + + if args.stats and not (args.create or args.prune): + raise ValueError('The --stats option can only be used when creating or pruning archives') - args.prune = True - args.create = True - args.check = True return args diff --git a/tests/integration/commands/test_borgmatic.py b/tests/integration/commands/test_borgmatic.py index 0dee6e2bd..d4f11b7bb 100644 --- a/tests/integration/commands/test_borgmatic.py +++ b/tests/integration/commands/test_borgmatic.py @@ -158,6 +158,10 @@ def test_parse_arguments_with_stats_flag_but_no_create_or_prune_flag_raises_valu module.parse_arguments('--stats', '--list') +def test_parse_arguments_with_just_stats_flag_does_not_raise(): + module.parse_arguments('--stats') + + def test_parse_arguments_allows_json_with_list_or_info(): module.parse_arguments('--list', '--json') module.parse_arguments('--info', '--json')