made more command line flags do things

This commit is contained in:
tigerbot 2017-05-24 18:20:02 -06:00
parent 3633c7570b
commit 2eb6d1bc95
1 changed files with 17 additions and 15 deletions

View File

@ -69,6 +69,7 @@ function readConfigAndRun(args) {
var recase = require('recase').create({}); var recase = require('recase').create({});
config = recase.camelCopy(config); config = recase.camelCopy(config);
config.debug = config.debug || args.debug;
if (!config.dns) { if (!config.dns) {
config.dns = { modules: [{ name: 'proxy', port: 3053 }] }; config.dns = { modules: [{ name: 'proxy', port: 3053 }] };
@ -85,15 +86,17 @@ function readConfigAndRun(args) {
config.http = { modules: [{ name: 'proxy', domains: ['*'], port: 3000 }] }; config.http = { modules: [{ name: 'proxy', domains: ['*'], port: 3000 }] };
} }
if (!config.tls) { if (!config.tls) {
console.log("TODO: tls: { modules: { name: 'acme', email: 'foo@bar.com', domains: [ '*' ] } }"); config.tls = {};
config.tls = { }
agreeTos: args.agreeTos || args.agree || args['agree-tos'] if (!config.tls.acme && (args.email || args.agreeTos)) {
, servernames: (args.servernames||'').split(',').filter(Boolean).map(function (str) { return str.toLowerCase(); }) config.tls.acme = {};
}; }
if (typeof args.agreeTos === 'string') {
config.tls.acme.approvedDomains = args.agreeTos.split(',');
} }
if (args.email) { if (args.email) {
config.email = args.email; config.email = args.email;
config.tls.email = args.email; config.tls.acme.email = args.email;
} }
// maybe this should not go in config... but be ephemeral in some way? // maybe this should not go in config... but be ephemeral in some way?
@ -195,20 +198,20 @@ function readConfigAndRun(args) {
function readEnv(args) { function readEnv(args) {
// TODO // TODO
try {
if (process.env.GOLDILOCKS_HOME) {
process.chdir(process.env.GOLDILOCKS_HOME);
}
} catch (err) {}
var env = { var env = {
tunnel: process.env.GOLDILOCKS_TUNNEL_TOKEN || process.env.GOLDILOCKS_TUNNEL && true tunnel: process.env.GOLDILOCKS_TUNNEL_TOKEN || process.env.GOLDILOCKS_TUNNEL && true
, email: process.env.GOLDILOCKS_EMAIL , email: process.env.GOLDILOCKS_EMAIL
, cwd: process.env.GOLDILOCKS_HOME , cwd: process.env.GOLDILOCKS_HOME || process.cwd()
, debug: process.env.GOLDILOCKS_DEBUG && true , debug: process.env.GOLDILOCKS_DEBUG && true
}; };
args.cwd = args.cwd || env.cwd;
Object.keys(env).forEach(function (key) {
if ('undefined' === typeof args[key]) {
args[key] = env[key];
}
});
readConfigAndRun(args); readConfigAndRun(Object.assign({}, env, args));
} }
var program = require('commander'); var program = require('commander');
@ -222,5 +225,4 @@ program
.option('--debug', "Enable debug output") .option('--debug', "Enable debug output")
.parse(process.argv); .parse(process.argv);
program.cwd = process.cwd();
readEnv(program); readEnv(program);