From 7173bee935bed9ab4d7e52d1386f32ff64ad7b72 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 29 Mar 2017 18:43:35 +0100 Subject: [PATCH] Allow validation --- md_pdf/cli.py | 2 ++ md_pdf/config/validate.py | 19 +++++++++++++++++++ md_pdf/exceptions.py | 4 ++++ 3 files changed, 25 insertions(+) diff --git a/md_pdf/cli.py b/md_pdf/cli.py index a34d545..bf10bed 100644 --- a/md_pdf/cli.py +++ b/md_pdf/cli.py @@ -3,6 +3,7 @@ from md_pdf.args import parse_args from md_pdf.exceptions import PrematureExit from md_pdf.build import build from md_pdf.config.read import load_config +from md_pdf.config.validate import validate_config FORMAT = "[%(levelname)s]: %(message)s" @@ -13,6 +14,7 @@ def cli(): args = parse_args() try: config = load_config() + validate_config(config) build(args, config) except PrematureExit: return 0 diff --git a/md_pdf/config/validate.py b/md_pdf/config/validate.py index e69de29..f01e83c 100644 --- a/md_pdf/config/validate.py +++ b/md_pdf/config/validate.py @@ -0,0 +1,19 @@ +from md_pdf.exceptions import ConfigValidationException + + +REQUIRED_KEYS = [ + 'output', + 'input' +] + + +def check_required_keys(config): + missing_keys = [key for key in REQUIRED_KEYS if key not in config] + if missing_keys: + raise ConfigValidationException("Missing required keys: {}".format(missing_keys)) + + +def validate_config(config): + check_required_keys(config) + + diff --git a/md_pdf/exceptions.py b/md_pdf/exceptions.py index abc8e8e..c608b52 100644 --- a/md_pdf/exceptions.py +++ b/md_pdf/exceptions.py @@ -1,2 +1,6 @@ class PrematureExit(Exception): pass + + +class ConfigValidationException(Exception): + pass