From c83012236a1ef2ef378c849b78691006838fc12a Mon Sep 17 00:00:00 2001 From: Bouke Haarsma Date: Mon, 3 Feb 2014 15:20:14 +0100 Subject: [PATCH] Fixed #134 -- Added CLI interface --- jsonschema/cli.py | 23 +++++++++++++++++++++++ setup.py | 3 +++ 2 files changed, 26 insertions(+) create mode 100644 jsonschema/cli.py 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'] + } )