Skip to content

Commit c830122

Browse files
committed
Fixed python-jsonschema#134 -- Added CLI interface
1 parent 121056f commit c830122

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

jsonschema/cli.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# encoding=utf-8
2+
3+
import argparse
4+
import json
5+
6+
from jsonschema import validate
7+
8+
def main():
9+
parser = argparse.ArgumentParser(description='JSON Schema validator')
10+
parser.add_argument('schema', help='filename of the JSON Schema')
11+
parser.add_argument('document', help='filename of the JSON document to validate')
12+
args = parser.parse_args()
13+
14+
schema = json.load(open(args.schema, 'r'))
15+
document = json.load(open(args.document, 'r'))
16+
17+
validate(document, schema)
18+
# validate raises if the document is invalid, and will show a Traceback to
19+
# the user. If the document is valid, show a congratulating message.
20+
print("√ JSON document is valid.")
21+
22+
if __name__ == '__main__':
23+
main()

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,7 @@
3636
license="MIT",
3737
long_description=long_description,
3838
url="http://github.com/Julian/jsonschema",
39+
entry_points = {
40+
'console_scripts': ['jsonschema = jsonschema.cli:main']
41+
}
3942
)

0 commit comments

Comments
 (0)