Skip to content

Commit

Permalink
Issue garycourt#39 - Command line interface
Browse files Browse the repository at this point in the history
  • Loading branch information
kewisch committed Oct 24, 2012
1 parent e539d4d commit b032799
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions examples/JSV.js
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!");
}

0 comments on commit b032799

Please sign in to comment.