allow for all configs with --all

This commit is contained in:
AJ ONeal 2019-11-03 10:10:27 -07:00
parent 40516a4c03
commit af3a2f621c
3 changed files with 56 additions and 35 deletions

View File

@ -10,11 +10,11 @@ var Flags = require('./lib/flags.js');
Flags.init().then(function({ flagOptions, rc, greenlock, mconf }) { Flags.init().then(function({ flagOptions, rc, greenlock, mconf }) {
var myFlags = {}; var myFlags = {};
['all', 'subject', 'servername' /*, 'servernames', 'altnames'*/].forEach(function( ['all', 'subject', 'servername' /*, 'servernames', 'altnames'*/].forEach(
k function(k) {
) {
myFlags[k] = flagOptions[k]; myFlags[k] = flagOptions[k];
}); }
);
cli.parse(myFlags); cli.parse(myFlags);
cli.main(function(argList, flags) { cli.main(function(argList, flags) {
@ -51,8 +51,15 @@ async function main(_, flags, rc, greenlock) {
} }
delete flags.servernames; delete flags.servernames;
greenlock var getter = function() {
._config(flags) return greenlock._config(flags);
};
if (flags.all) {
getter = function() {
return greenlock._configAll(flags);
};
}
return getter()
.catch(function(err) { .catch(function(err) {
console.error(); console.error();
console.error('error:', err.message); console.error('error:', err.message);
@ -60,19 +67,30 @@ async function main(_, flags, rc, greenlock) {
console.error(); console.error();
process.exit(1); process.exit(1);
}) })
.then(function(site) { .then(function(sites) {
if (!site) { if (!sites) {
console.info(); console.info();
if (flags.all) {
console.info('No configs found');
} else {
console.info('No config found for', flags.servername); console.info('No config found for', flags.servername);
}
console.info(); console.info();
process.exit(1); process.exit(1);
return; return;
} }
if (!Array.isArray(sites)) {
sites = [sites];
}
sites.forEach(function(site) {
console.info(); console.info();
console.info( console.info(
'Config for ' + JSON.stringify(flags.servername) + ':' 'Config for ' +
JSON.stringify(flags.servername || site.subject) +
':'
); );
console.info(JSON.stringify(site, null, 2)); console.info(JSON.stringify(site, null, 2));
}); });
});
} }

View File

@ -119,7 +119,7 @@ CLI.main = function(cb, args) {
// only long names are actually used // only long names are actually used
if ('--' !== flag.slice(0, 2)) { if ('--' !== flag.slice(0, 2)) {
console.error("Unrecognized argument '" + flag + "'"); console.error("error: unrecognized flag '" + flag + "'");
process.exit(1); process.exit(1);
} }
@ -131,7 +131,7 @@ CLI.main = function(cb, args) {
} }
// other arbitrary args are not used // other arbitrary args are not used
console.error("Unrecognized flag '" + flag + "'"); console.error("unrecognized elided flag '" + flag + "'");
process.exit(1); process.exit(1);
} }

View File

@ -278,7 +278,9 @@ G.create = function(gconf) {
greenlock._config = function(args) { greenlock._config = function(args) {
return greenlock._single(args).then(function() { return greenlock._single(args).then(function() {
return greenlock._configAll(args); return greenlock._configAll(args).then(function (sites) {
return sites[0];
});
}); });
}; };
greenlock._configAll = function(args) { greenlock._configAll = function(args) {
@ -286,8 +288,9 @@ G.create = function(gconf) {
if (!sites || !sites.length) { if (!sites || !sites.length) {
return null; return null;
} }
var site = sites[0]; sites = JSON.parse(JSON.stringify(sites));
site = JSON.parse(JSON.stringify(site)); return manager.defaults().then(function(mconf) {
return sites.map(function(site) {
if (site.store && site.challenges) { if (site.store && site.challenges) {
return site; return site;
} }
@ -296,7 +299,6 @@ G.create = function(gconf) {
if (gconf._bin_mode) { if (gconf._bin_mode) {
dconf = site.defaults = {}; dconf = site.defaults = {};
} }
return manager.defaults().then(function(mconf) {
if (!site.store) { if (!site.store) {
dconf.store = mconf.store; dconf.store = mconf.store;
} }
@ -306,6 +308,7 @@ G.create = function(gconf) {
return site; return site;
}); });
}); });
});
}; };
// needs to get info about the renewal, such as which store and challenge(s) to use // needs to get info about the renewal, such as which store and challenge(s) to use