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

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