Handle and format validation errors raised during argument parsing (#136).

This commit is contained in:
Dan Helfman 2019-01-27 11:58:04 -08:00
parent d9018a47f6
commit 031b9d6faf
2 changed files with 18 additions and 3 deletions

1
NEWS
View file

@ -1,4 +1,5 @@
1.2.15.dev0
* #136: Handle and format validation errors raised during argument parsing.
1.2.14
* #103: When generating sample configuration with generate-borgmatic-config, document the defaults

View file

@ -350,9 +350,24 @@ def collect_configuration_run_summary_logs(config_filenames, args):
)
def exit_with_help_link(): # pragma: no cover
'''
Display a link to get help and exit with an error code.
'''
logger.critical('\nNeed some help? https://torsion.org/borgmatic/#issues')
sys.exit(1)
def main(): # pragma: no cover
configure_signals()
args = parse_arguments(*sys.argv[1:])
try:
args = parse_arguments(*sys.argv[1:])
except ValueError as error:
logging.basicConfig(level=logging.CRITICAL, format='%(message)s')
logger.critical(error)
exit_with_help_link()
logging.basicConfig(level=verbosity_to_log_level(args.verbosity), format='%(message)s')
if args.version:
@ -369,5 +384,4 @@ def main(): # pragma: no cover
[logger.handle(log) for log in summary_logs if log.levelno >= logger.getEffectiveLevel()]
if any(log.levelno == logging.CRITICAL for log in summary_logs):
logger.critical('\nNeed some help? https://torsion.org/borgmatic/#issues')
sys.exit(1)
exit_with_help_link()