From a836ec944f523db42f25284c5c552742cc57907d Mon Sep 17 00:00:00 2001 From: floli Date: Tue, 18 Sep 2018 05:31:27 +0000 Subject: [PATCH] Limit argument range for --verbose, make default log level more explicit. (#93) --- borgmatic/commands/borgmatic.py | 2 ++ borgmatic/tests/integration/commands/test_borgmatic.py | 6 +++--- borgmatic/verbosity.py | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 051179d..8d99b31 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -92,6 +92,8 @@ def parse_arguments(*arguments): parser.add_argument( '-v', '--verbosity', type=int, + choices=range(0,3), + default=0, help='Display verbose progress (1 for some, 2 for lots)', ) diff --git a/borgmatic/tests/integration/commands/test_borgmatic.py b/borgmatic/tests/integration/commands/test_borgmatic.py index bd5f3e7..49225bf 100644 --- a/borgmatic/tests/integration/commands/test_borgmatic.py +++ b/borgmatic/tests/integration/commands/test_borgmatic.py @@ -14,7 +14,7 @@ def test_parse_arguments_with_no_arguments_uses_defaults(): assert parser.config_paths == config_paths assert parser.excludes_filename == None - assert parser.verbosity is None + assert parser.verbosity is 0 assert parser.json is False @@ -25,7 +25,7 @@ def test_parse_arguments_with_path_arguments_overrides_defaults(): assert parser.config_paths == ['myconfig'] assert parser.excludes_filename == 'myexcludes' - assert parser.verbosity is None + assert parser.verbosity is 0 def test_parse_arguments_with_multiple_config_paths_parses_as_list(): @@ -34,7 +34,7 @@ def test_parse_arguments_with_multiple_config_paths_parses_as_list(): parser = module.parse_arguments('--config', 'myconfig', 'otherconfig') assert parser.config_paths == ['myconfig', 'otherconfig'] - assert parser.verbosity is None + assert parser.verbosity is 0 def test_parse_arguments_with_verbosity_flag_overrides_default(): diff --git a/borgmatic/verbosity.py b/borgmatic/verbosity.py index 91264e4..8444a0b 100644 --- a/borgmatic/verbosity.py +++ b/borgmatic/verbosity.py @@ -1,6 +1,7 @@ import logging +VERBOSITY_WARNING = 0 VERBOSITY_SOME = 1 VERBOSITY_LOTS = 2 @@ -10,6 +11,7 @@ def verbosity_to_log_level(verbosity): Given a borgmatic verbosity value, return the corresponding Python log level. ''' return { + VERBOSITY_WARNING: logging.WARNING, VERBOSITY_SOME: logging.INFO, VERBOSITY_LOTS: logging.DEBUG, }.get(verbosity, logging.WARNING)