Allow validation
This commit is contained in:
parent
7bbe0cbcd6
commit
7173bee935
3 changed files with 25 additions and 0 deletions
|
@ -3,6 +3,7 @@ from md_pdf.args import parse_args
|
||||||
from md_pdf.exceptions import PrematureExit
|
from md_pdf.exceptions import PrematureExit
|
||||||
from md_pdf.build import build
|
from md_pdf.build import build
|
||||||
from md_pdf.config.read import load_config
|
from md_pdf.config.read import load_config
|
||||||
|
from md_pdf.config.validate import validate_config
|
||||||
|
|
||||||
|
|
||||||
FORMAT = "[%(levelname)s]: %(message)s"
|
FORMAT = "[%(levelname)s]: %(message)s"
|
||||||
|
@ -13,6 +14,7 @@ def cli():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
try:
|
try:
|
||||||
config = load_config()
|
config = load_config()
|
||||||
|
validate_config(config)
|
||||||
build(args, config)
|
build(args, config)
|
||||||
except PrematureExit:
|
except PrematureExit:
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,6 @@
|
||||||
class PrematureExit(Exception):
|
class PrematureExit(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigValidationException(Exception):
|
||||||
|
pass
|
||||||
|
|
Reference in a new issue