From 8c4594f399de85331c0707e7d5e67cbd0dc66a98 Mon Sep 17 00:00:00 2001 From: tigerbot Date: Sat, 6 May 2017 12:04:46 -0600 Subject: [PATCH] fixed problem specifying config file --- bin/goldilocks.js | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/bin/goldilocks.js b/bin/goldilocks.js index 6886619..ffe8aad 100755 --- a/bin/goldilocks.js +++ b/bin/goldilocks.js @@ -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 ', "(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 ', "(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);