diff --git a/jsonschema/cli.py b/jsonschema/cli.py new file mode 100644 index 000000000..4412aa616 --- /dev/null +++ b/jsonschema/cli.py @@ -0,0 +1,23 @@ +# encoding=utf-8 + +import argparse +import json + +from jsonschema import validate + +def main(): + parser = argparse.ArgumentParser(description='JSON Schema validator') + parser.add_argument('schema', help='filename of the JSON Schema') + parser.add_argument('document', help='filename of the JSON document to validate') + args = parser.parse_args() + + schema = json.load(open(args.schema, 'r')) + document = json.load(open(args.document, 'r')) + + validate(document, schema) + # validate raises if the document is invalid, and will show a Traceback to + # the user. If the document is valid, show a congratulating message. + print("√ JSON document is valid.") + +if __name__ == '__main__': + main() diff --git a/setup.py b/setup.py index 5f38d6e79..dd4bff668 100644 --- a/setup.py +++ b/setup.py @@ -36,4 +36,7 @@ license="MIT", long_description=long_description, url="http://github.com/Julian/jsonschema", + entry_points = { + 'console_scripts': ['jsonschema = jsonschema.cli:main'] + } )