#!/usr/bin/env python3

#
# Development Order #6:
#
# This file accepts a test spec through stdin and outputs whether
# or not it was validated through stdout.
#
# This can be tested directly using the following syntax:
# ./cli-to-spec --option argument | ./spec-is-valid

import pscheduler

from validate import spec_is_valid

try:
    json = pscheduler.json_load()
except ValueError as ex:
    pscheduler.succeed_json({
        "valid": False,
        "error": str(ex)
    })

valid, message = spec_is_valid(json)

result = {
    "valid": valid
}

if not valid:
    result["error"] = message

pscheduler.succeed_json(result)
