From af3a2f621cc8e42866fda9718ae8da6657978cf0 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sun, 3 Nov 2019 10:10:27 -0700 Subject: [PATCH] allow for all configs with --all --- bin/config.js | 48 +++++++++++++++++++++++++++++++++--------------- bin/lib/cli.js | 4 ++-- greenlock.js | 39 +++++++++++++++++++++------------------ 3 files changed, 56 insertions(+), 35 deletions(-) diff --git a/bin/config.js b/bin/config.js index e31a86a..2e73056 100644 --- a/bin/config.js +++ b/bin/config.js @@ -10,11 +10,11 @@ var Flags = require('./lib/flags.js'); Flags.init().then(function({ flagOptions, rc, greenlock, mconf }) { var myFlags = {}; - ['all', 'subject', 'servername' /*, 'servernames', 'altnames'*/].forEach(function( - k - ) { - myFlags[k] = flagOptions[k]; - }); + ['all', 'subject', 'servername' /*, 'servernames', 'altnames'*/].forEach( + function(k) { + myFlags[k] = flagOptions[k]; + } + ); cli.parse(myFlags); cli.main(function(argList, flags) { @@ -51,8 +51,15 @@ async function main(_, flags, rc, greenlock) { } delete flags.servernames; - greenlock - ._config(flags) + var getter = function() { + return greenlock._config(flags); + }; + if (flags.all) { + getter = function() { + return greenlock._configAll(flags); + }; + } + return getter() .catch(function(err) { console.error(); console.error('error:', err.message); @@ -60,19 +67,30 @@ async function main(_, flags, rc, greenlock) { console.error(); process.exit(1); }) - .then(function(site) { - if (!site) { + .then(function(sites) { + if (!sites) { console.info(); - console.info('No config found for', flags.servername); + if (flags.all) { + console.info('No configs found'); + } else { + console.info('No config found for', flags.servername); + } console.info(); process.exit(1); return; } + if (!Array.isArray(sites)) { + sites = [sites]; + } - console.info(); - console.info( - 'Config for ' + JSON.stringify(flags.servername) + ':' - ); - console.info(JSON.stringify(site, null, 2)); + sites.forEach(function(site) { + console.info(); + console.info( + 'Config for ' + + JSON.stringify(flags.servername || site.subject) + + ':' + ); + console.info(JSON.stringify(site, null, 2)); + }); }); } diff --git a/bin/lib/cli.js b/bin/lib/cli.js index 789c2e7..cff83f4 100644 --- a/bin/lib/cli.js +++ b/bin/lib/cli.js @@ -119,7 +119,7 @@ CLI.main = function(cb, args) { // only long names are actually used if ('--' !== flag.slice(0, 2)) { - console.error("Unrecognized argument '" + flag + "'"); + console.error("error: unrecognized flag '" + flag + "'"); process.exit(1); } @@ -131,7 +131,7 @@ CLI.main = function(cb, args) { } // other arbitrary args are not used - console.error("Unrecognized flag '" + flag + "'"); + console.error("unrecognized elided flag '" + flag + "'"); process.exit(1); } diff --git a/greenlock.js b/greenlock.js index fdf3dd8..22122be 100644 --- a/greenlock.js +++ b/greenlock.js @@ -278,7 +278,9 @@ G.create = function(gconf) { greenlock._config = function(args) { return greenlock._single(args).then(function() { - return greenlock._configAll(args); + return greenlock._configAll(args).then(function (sites) { + return sites[0]; + }); }); }; greenlock._configAll = function(args) { @@ -286,24 +288,25 @@ G.create = function(gconf) { if (!sites || !sites.length) { return null; } - var site = sites[0]; - site = JSON.parse(JSON.stringify(site)); - if (site.store && site.challenges) { - return site; - } - var dconf = site; - // TODO make cli and api mode the same - if (gconf._bin_mode) { - dconf = site.defaults = {}; - } + sites = JSON.parse(JSON.stringify(sites)); return manager.defaults().then(function(mconf) { - if (!site.store) { - dconf.store = mconf.store; - } - if (!site.challenges) { - dconf.challenges = mconf.challenges; - } - return site; + return sites.map(function(site) { + if (site.store && site.challenges) { + return site; + } + var dconf = site; + // TODO make cli and api mode the same + if (gconf._bin_mode) { + dconf = site.defaults = {}; + } + if (!site.store) { + dconf.store = mconf.store; + } + if (!site.challenges) { + dconf.challenges = mconf.challenges; + } + return site; + }); }); }); };