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 }) {
var myFlags = {};
['all', 'subject', 'servername' /*, 'servernames', 'altnames'*/].forEach(function(
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();
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];
}
sites.forEach(function(site) {
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));
});
});
}

View File

@ -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);
}

View File

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