};
util.inherits(Config, events.EventEmitter);
-Config.prototype.loadConfig = function () {
+Config.prototype.loadConfig = function (manual_config_file) {
var new_config,
conf_filepath,
i;
- // Loop through the possible config paths and find a usable one
- for (i = 0; i < config_dirs.length; i++) {
- conf_filepath = config_dirs[i] + config_filename;
+ if (manual_config_file) {
+ if (fs.existsSync(manual_config_file)) {
+ try {
+ if (fs.lstatSync(manual_config_file).isFile() === true) {
+ // Clear the loaded config cache
+ delete require.cache[require.resolve(manual_config_file)];
- try {
- if (fs.lstatSync(conf_filepath).isFile() === true) {
- // Clear the loaded config cache
- delete require.cache[require.resolve(conf_filepath)];
-
- // Try load the new config file
- new_config = require(conf_filepath);
- break;
+ // Try load the new config file
+ new_config = require(manual_config_file);
+ }
+ } catch (e) {
+ console.log('An error occured parsing the config file ' + manual_config_file + ': ' + e.message);
+ process.exit(1);
}
- } catch (e) {
- switch (e.code) {
- case 'ENOENT': // No file/dir
- break;
- default:
- console.log('An error occured parsing the config file ' + config_dirs[i] + config_filename + ': ' + e.message);
- return false;
+ } else {
+ console.log('Could not find config file ' + manual_config_file);
+ process.exit(1);
+ }
+ } else {
+ // Loop through the possible config paths and find a usable one
+ for (i = 0; i < config_dirs.length; i++) {
+ conf_filepath = config_dirs[i] + config_filename;
+
+ try {
+ if (fs.lstatSync(conf_filepath).isFile() === true) {
+ // Clear the loaded config cache
+ delete require.cache[require.resolve(conf_filepath)];
+
+ // Try load the new config file
+ new_config = require(conf_filepath);
+ break;
+ }
+ } catch (e) {
+ switch (e.code) {
+ case 'ENOENT': // No file/dir
+ break;
+ default:
+ console.log('An error occured parsing the config file ' + config_dirs[i] + config_filename + ': ' + e.message);
+ return false;
+ }
+ continue;
}
- continue;
}
}
process.chdir(__dirname + '/../');
-config.loadConfig();
+
+(function (argv) {
+ var conf_switch = argv.indexOf('-c');
+ if (conf_switch !== -1) {
+ if (argv[conf_switch + 1]) {
+ return config.loadConfig(argv[conf_switch + 1]);
+ }
+ }
+
+ config.loadConfig();
+
+})(process.argv);
// If we're not running in the forground and we have a log file.. switch