File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55import json
66import sys
77from datetime import datetime
8+ import jsonschema
89from google .cloud import bigquery
910from google .api_core .exceptions import BadRequest
1011from kcidb import db_schema
@@ -212,3 +213,23 @@ def schema_main():
212213 parser = argparse .ArgumentParser (description = description )
213214 parser .parse_args ()
214215 json .dump (io_schema .JSON , sys .stdout , indent = 4 , sort_keys = True )
216+
217+
218+ def validate_main ():
219+ """Execute the kcidb-validate command-line tool"""
220+ description = 'kcidb-validate - Validate I/O JSON data'
221+ parser = argparse .ArgumentParser (description = description )
222+ parser .parse_args ()
223+
224+ try :
225+ data = json .load (sys .stdin )
226+ except json .decoder .JSONDecodeError as err :
227+ print (err , sys .stderr )
228+ return 1
229+
230+ try :
231+ io_schema .validate (data )
232+ except jsonschema .exceptions .ValidationError as err :
233+ print (err , sys .stderr )
234+ return 2
235+ return 0
Original file line number Diff line number Diff line change 5252 "kcidb-init = kcidb:init_main" ,
5353 "kcidb-cleanup = kcidb:cleanup_main" ,
5454 "kcidb-schema = kcidb:schema_main" ,
55+ "kcidb-validate = kcidb:validate_main" ,
5556 "kcidb-submit = kcidb:submit_main" ,
5657 "kcidb-query = kcidb:query_main" ,
5758 ]
You can’t perform that action at this time.
0 commit comments