Allow validation

This commit is contained in:
Jake Howard 2017-03-29 18:43:35 +01:00
parent 7bbe0cbcd6
commit 7173bee935
3 changed files with 25 additions and 0 deletions

View file

@ -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

View file

@ -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)

View file

@ -1,2 +1,6 @@
class PrematureExit(Exception):
pass
class ConfigValidationException(Exception):
pass