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();
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(); console.info();
process.exit(1); process.exit(1);
return; return;
} }
if (!Array.isArray(sites)) {
sites = [sites];
}
console.info(); sites.forEach(function(site) {
console.info( console.info();
'Config for ' + JSON.stringify(flags.servername) + ':' console.info(
); 'Config for ' +
console.info(JSON.stringify(site, null, 2)); JSON.stringify(flags.servername || site.subject) +
':'
);
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,24 +288,25 @@ 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));
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 = {};
}
return manager.defaults().then(function(mconf) { return manager.defaults().then(function(mconf) {
if (!site.store) { return sites.map(function(site) {
dconf.store = mconf.store; if (site.store && site.challenges) {
} return site;
if (!site.challenges) { }
dconf.challenges = mconf.challenges; var dconf = site;
} // TODO make cli and api mode the same
return site; if (gconf._bin_mode) {
dconf = site.defaults = {};
}
if (!site.store) {
dconf.store = mconf.store;
}
if (!site.challenges) {
dconf.challenges = mconf.challenges;
}
return site;
});
}); });
}); });
}; };