forked from garycourt/JSV
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue garycourt#39 - Command line interface
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var fs = require("fs"); | ||
var JSV = require("../lib/jsv.js").JSV; | ||
|
||
var env = JSV.createEnvironment(); | ||
var baseURI = "schema"; | ||
var userURI = "user"; | ||
var userData, schemaData; | ||
|
||
if (process.argv.length < 4) { | ||
console.error("Usage: JSV.js [schema.js] [userdata.js]"); | ||
return; | ||
} | ||
|
||
var schemaData = JSON.parse(fs.readFileSync(process.argv[2])); | ||
var userData = JSON.parse(fs.readFileSync(process.argv[3])); | ||
|
||
var instance = env.createInstance(userData, "urn:jsv:data"); | ||
var schema = env.createSchema(schemaData, null, "urn:jsv:schema"); | ||
|
||
var report = env.validate(instance, schema); | ||
|
||
if (report.errors.length) { | ||
for (var x = 0, xl = report.errors.length; x < xl; x++) { | ||
var err = report.errors[x]; | ||
console.log('Problem with ' + err.uri + ': ' + err.message); | ||
console.log(' Reported by ' + err.schemaUri); | ||
console.log(' Attribute "' + err.attribute + '" (' + JSON.stringify(err.details) + ')'); | ||
} | ||
} else { | ||
console.log("Input is valid!"); | ||
} |