Allow use of --stats flag when --create or --prune flags are implied (#139).

This commit is contained in:
Dan Helfman 2019-01-27 12:15:47 -08:00
parent 031b9d6faf
commit 2dc006aab4
3 changed files with 19 additions and 8 deletions

1
NEWS
View file

@ -1,5 +1,6 @@
1.2.15.dev0 1.2.15.dev0
* #136: Handle and format validation errors raised during argument parsing. * #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 1.2.14
* #103: When generating sample configuration with generate-borgmatic-config, document the defaults * #103: When generating sample configuration with generate-borgmatic-config, document the defaults

View file

@ -166,9 +166,6 @@ def parse_arguments(*arguments):
if args.progress and not args.create: if args.progress and not args.create:
raise ValueError('The --progress option can only be used with the --create option') 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): if args.json and not (args.create or args.list or args.info):
raise ValueError( raise ValueError(
'The --json option can only be used with the --create, --list, or --info options' '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 # 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. # 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: if (
return args 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.prune = True
args.create = True args.create = True
args.check = 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')
return args return args

View file

@ -158,6 +158,10 @@ def test_parse_arguments_with_stats_flag_but_no_create_or_prune_flag_raises_valu
module.parse_arguments('--stats', '--list') 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(): def test_parse_arguments_allows_json_with_list_or_info():
module.parse_arguments('--list', '--json') module.parse_arguments('--list', '--json')
module.parse_arguments('--info', '--json') module.parse_arguments('--info', '--json')