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) {
var fs = require('fs');
var path = require('path');
var cwd = args.cwd;
var cwd = args.cwd || process.cwd();
var text;
var filename;
var 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 {
filename = path.join(cwd, 'goldilocks.yml');
@ -196,29 +197,16 @@ function readEnv(args) {
readConfigAndRun(args);
}
if (process.argv.length === 2) {
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');
var program = require('commander');
program
.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('--config', '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('--email <email>', "(Re)set default email to use for Daplie, Let's Encrypt, ACME, etc.")
.option('--debug', "Enable debug output")
.parse(process.argv);
program
.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('-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('--email <email>', "(Re)set default email to use for Daplie, Let's Encrypt, ACME, etc.")
.option('--debug', "Enable debug output")
.parse(process.argv);
program.cwd = process.cwd();
readEnv(program);
}
else {
throw new Error("impossible number of arguments: " + process.argv.length);
}
program.cwd = process.cwd();
readEnv(program);