Get config.json location from command line parameter.
This commit is contained in:
parent
856371a8ce
commit
2a2a2b72e9
2 changed files with 34 additions and 1 deletions
|
@ -20,6 +20,8 @@
|
|||
"dependencies": {
|
||||
"async": "~1.5.2",
|
||||
"body-parser": "~1.15.1",
|
||||
"command-line-args": "~3.0.0",
|
||||
"command-line-usage": "~3.0.1",
|
||||
"compression": "~1.6.2",
|
||||
"deep-extend": "~0.4.1",
|
||||
"express": "~4.13.4",
|
||||
|
|
|
@ -1,5 +1,33 @@
|
|||
'use strict';
|
||||
|
||||
var commandLineArgs = require('command-line-args');
|
||||
var commandLineUsage = require('command-line-usage');
|
||||
|
||||
var commandLineDefs = [
|
||||
{ name: 'help', alias: 'h', type: Boolean, description: 'Show this help' },
|
||||
{ name: 'config', alias: 'c', type: String, description: 'Location of config.json' }
|
||||
];
|
||||
|
||||
var commandLineOptions;
|
||||
try {
|
||||
commandLineOptions = commandLineArgs(commandLineDefs);
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
console.error('Try \'--help\' for more information.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (commandLineOptions.help || !commandLineOptions.config) {
|
||||
console.log(commandLineUsage([
|
||||
{
|
||||
header: 'ffffng - Freifunk node management form',
|
||||
optionList: commandLineDefs
|
||||
}
|
||||
]));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
||||
var fs = require('fs');
|
||||
var deepExtend = require('deep-extend');
|
||||
|
||||
|
@ -65,11 +93,14 @@ var defaultConfig = {
|
|||
}
|
||||
};
|
||||
|
||||
var configJSONFile = __dirname + '/../config.json';
|
||||
var configJSONFile = commandLineOptions.config;
|
||||
var configJSON = {};
|
||||
|
||||
if (fs.existsSync(configJSONFile)) {
|
||||
configJSON = JSON.parse(fs.readFileSync(configJSONFile, 'utf8'));
|
||||
} else {
|
||||
console.error('config.json not found: ' + configJSONFile);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var config = deepExtend({}, defaultConfig, configJSON);
|
||||
|
|
Loading…
Reference in a new issue