fixed problem specifying config file

This commit is contained in:
tigerbot 2017-05-06 12:04:46 -06:00
parent 2414163179
commit 8c4594f399
1 changed files with 14 additions and 26 deletions

View File

@ -26,13 +26,14 @@ function run(config) {
function readConfigAndRun(args) { function readConfigAndRun(args) {
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var cwd = args.cwd; var cwd = args.cwd || process.cwd();
var text; var text;
var filename; var filename;
var config; var config;
if (args.config) { if (args.config) {
text = fs.readFileSync(path.join(cwd, args.config), 'utf8'); filename = path.join(cwd, args.config);
text = fs.readFileSync(filename, 'utf8');
} }
else { else {
filename = path.join(cwd, 'goldilocks.yml'); filename = path.join(cwd, 'goldilocks.yml');
@ -196,29 +197,16 @@ function readEnv(args) {
readConfigAndRun(args); readConfigAndRun(args);
} }
if (process.argv.length === 2) { var program = require('commander');
readEnv({ cwd: process.cwd() });
}
else if (process.argv.length === 4) {
if ('-c' === process.argv[3] || '--config' === process.argv[3]) {
readEnv({ config: process.argv[4] });
}
}
else if (process.argv.length > 2) {
var program = require('commander');
program program
.version(require('../package.json').version) .version(require('../package.json').version)
.option('--agree-tos [url1,url2]', "agree to all Terms of Service for Daplie, Let's Encrypt, etc (or specific URLs only)") .option('--agree-tos [url1,url2]', "agree to all Terms of Service for Daplie, Let's Encrypt, etc (or specific URLs only)")
.option('--config', 'Path to config file (Goldilocks.json or Goldilocks.yml) example: --config /etc/goldilocks/Goldilocks.json') .option('-c --config [file]', 'Path to config file (Goldilocks.json or Goldilocks.yml) example: --config /etc/goldilocks/Goldilocks.json')
.option('--tunnel [token]', 'Turn tunnel on. This will enter interactive mode for login if no token is specified.') .option('--tunnel [token]', 'Turn tunnel on. This will enter interactive mode for login if no token is specified.')
.option('--email <email>', "(Re)set default email to use for Daplie, Let's Encrypt, ACME, etc.") .option('--email <email>', "(Re)set default email to use for Daplie, Let's Encrypt, ACME, etc.")
.option('--debug', "Enable debug output") .option('--debug', "Enable debug output")
.parse(process.argv); .parse(process.argv);
program.cwd = process.cwd(); program.cwd = process.cwd();
readEnv(program); readEnv(program);
}
else {
throw new Error("impossible number of arguments: " + process.argv.length);
}