Commit c6ae337d authored by Leo Iannacone's avatar Leo Iannacone

added parser options - defined first options -c and -h

parent 27568418
...@@ -117,12 +117,20 @@ function _merge(object1, object2) { ...@@ -117,12 +117,20 @@ function _merge(object1, object2) {
} }
try { try {
user_config = require('../user.config.js') var Parser = require('./parser.js')
console.log("Reading user configutation ...") var parser = new Parser()
config = _merge(config, user_config) var user_config = parser.getUserConfig()
if (user_config) {
console.log("Reading user configutation ...")
config = _merge(config, require(user_config))
}
else {
console.log("No user config specified. Using global settings.")
}
} catch (err) { } catch (err) {
if (err.code == 'MODULE_NOT_FOUND') { if (err.code == 'MODULE_NOT_FOUND') {
console.log("User configutation not found. Using global settings.") console.log("File %s not found.", user_config)
process.exit(1)
} }
else { else {
console.error("Error reading user configutation", err); console.error("Error reading user configutation", err);
......
function Parser()
{
var args = process.argv.slice(2);
var help = function() {
console.log("\
Usage: %s [-c config]\n\
-h print this help \n\
-c set user configuration file",
process.argv[1].split('/').pop());
process.exit(0);
}
this.getUserConfig = function() {
var configFile = null;
args.forEach(function (val, index) {
if (val == '-c') {
configFile = args[index+1]
return
}
})
if (configFile)
return process.cwd() + '/' + configFile;
else
return null
}
args.forEach(function (val, index) {
if (val == '-h') {
help()
}
})
}
module.exports = Parser
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment