Fixed all console input cases
This commit is contained in:
parent
fd7e427a22
commit
29293e4432
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
/*! @license ©2014 Miel Vander Sande - Multimedia Lab / iMinds / Ghent University */
|
/*! @license ©2014 Miel Vander Sande - Multimedia Lab / iMinds / Ghent University */
|
||||||
/* Command-line utility to validate Turtle files. */
|
/* Command-line utility to validate Turtle files. */
|
||||||
|
|
||||||
|
@ -6,6 +7,7 @@ var N3 = require('n3'),
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
N3Util = N3.Util,
|
N3Util = N3.Util,
|
||||||
http = require('http'),
|
http = require('http'),
|
||||||
|
url = require('url'),
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
validate = require('./lib/validator.js');
|
validate = require('./lib/validator.js');
|
||||||
|
|
||||||
|
@ -22,11 +24,28 @@ var help = function () {
|
||||||
console.log(' $ ttl http://triples.demo.thedatatank.com/demo.ttl');
|
console.log(' $ ttl http://triples.demo.thedatatank.com/demo.ttl');
|
||||||
};
|
};
|
||||||
|
|
||||||
if (process.argv[2] && (process.argv[2] === "-h" || process.argv[2] === "--help") ) {
|
var args = process.argv.slice(2);
|
||||||
help();
|
|
||||||
} else if (process.argv.length === 2) {
|
if (args.length > 1 || (args.length > 0 && (args[0] === "-h" || args[0] === "--help")))
|
||||||
// Use stdio as an input stream
|
return help();
|
||||||
validate(process.stdin, function (feedback) {
|
|
||||||
|
if (args.length === 0) {
|
||||||
|
validate(process.stdin, showValidation);
|
||||||
|
} else if (args.length > 0) {
|
||||||
|
// Create a stream from the file, whether it is a local file or a http stream
|
||||||
|
var parsedUrl = url.parse(args[0]);
|
||||||
|
if (parsedUrl.protocol === 'http:')
|
||||||
|
http.get(parsedUrl.href, function (res) {
|
||||||
|
validate(res, showValidation);
|
||||||
|
}).on('error', function (e) {
|
||||||
|
console.log("Got error: " + e.message);
|
||||||
|
});
|
||||||
|
else
|
||||||
|
validate(fs.createReadStream(parsedUrl.href), showValidation);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use stdio as an input stream
|
||||||
|
function showValidation(feedback) {
|
||||||
feedback.errors.forEach(function (error) {
|
feedback.errors.forEach(function (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
|
@ -34,26 +53,4 @@ if (process.argv[2] && (process.argv[2] === "-h" || process.argv[2] === "--help"
|
||||||
console.log(warning);
|
console.log(warning);
|
||||||
});
|
});
|
||||||
console.log("Validator finished with " + feedback.warnings.length + " warnings and " + feedback.errors.length + " errors.");
|
console.log("Validator finished with " + feedback.warnings.length + " warnings and " + feedback.errors.length + " errors.");
|
||||||
});
|
|
||||||
} else if (process.argv.length === 3 ) {
|
|
||||||
// Create a stream from the file, whether it is a local file or a http stream
|
|
||||||
var filename = process.argv[2];
|
|
||||||
fs.exists(filename, function (exists) {
|
|
||||||
if (exists) {
|
|
||||||
try{
|
|
||||||
validateStream(fs.createReadStream(filename));
|
|
||||||
} catch ( e ) {
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try{
|
|
||||||
validateStream(http.get(process.argv[2]));
|
|
||||||
} catch ( e ) {
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
|
||||||
help();
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue