2019-11-03 01:33:12 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var args = process.argv.slice(3);
|
2019-11-03 07:58:01 +00:00
|
|
|
var cli = require('./lib/cli.js');
|
2019-11-03 01:33:12 +00:00
|
|
|
//var path = require('path');
|
|
|
|
//var pkgpath = path.join(__dirname, '..', 'package.json');
|
|
|
|
//var pkgpath = path.join(process.cwd(), 'package.json');
|
|
|
|
|
2019-11-03 07:58:01 +00:00
|
|
|
var Flags = require('./lib/flags.js');
|
2019-11-03 01:33:12 +00:00
|
|
|
|
2019-11-19 05:55:29 +00:00
|
|
|
Flags.init().then(function({ flagOptions, greenlock, mconf }) {
|
2019-11-03 01:33:12 +00:00
|
|
|
var myFlags = {};
|
2019-11-03 17:10:27 +00:00
|
|
|
['all', 'subject', 'servername' /*, 'servernames', 'altnames'*/].forEach(
|
|
|
|
function(k) {
|
|
|
|
myFlags[k] = flagOptions[k];
|
|
|
|
}
|
|
|
|
);
|
2019-11-03 01:33:12 +00:00
|
|
|
|
|
|
|
cli.parse(myFlags);
|
|
|
|
cli.main(function(argList, flags) {
|
|
|
|
Flags.mangleFlags(flags, mconf);
|
2019-11-19 05:55:29 +00:00
|
|
|
main(argList, flags, greenlock);
|
2019-11-03 01:33:12 +00:00
|
|
|
}, args);
|
|
|
|
});
|
|
|
|
|
2019-11-19 05:55:29 +00:00
|
|
|
async function main(_, flags, greenlock) {
|
2019-11-03 01:33:12 +00:00
|
|
|
var servernames = [flags.subject]
|
|
|
|
.concat([flags.servername])
|
|
|
|
//.concat(flags.servernames)
|
|
|
|
//.concat(flags.altnames)
|
|
|
|
.filter(Boolean);
|
|
|
|
delete flags.subject;
|
|
|
|
delete flags.altnames;
|
|
|
|
flags.servernames = servernames;
|
2019-11-03 17:01:32 +00:00
|
|
|
if (!flags.all && flags.servernames.length > 1) {
|
|
|
|
console.error('Error: should specify either --subject OR --servername');
|
2019-11-03 01:33:12 +00:00
|
|
|
process.exit(1);
|
|
|
|
return;
|
2019-11-03 17:01:32 +00:00
|
|
|
} else if (!flags.all && flags.servernames.length !== 1) {
|
|
|
|
console.error('error: missing --servername <example.com>');
|
2019-11-03 01:33:12 +00:00
|
|
|
process.exit(1);
|
|
|
|
return;
|
|
|
|
}
|
2019-11-03 17:01:32 +00:00
|
|
|
if (!flags.all) {
|
|
|
|
flags.servername = flags.servernames[0];
|
|
|
|
} else if (flags.servername) {
|
|
|
|
console.error(
|
|
|
|
'error: missing cannot have --all and --servername / --subject'
|
|
|
|
);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2019-11-03 01:33:12 +00:00
|
|
|
delete flags.servernames;
|
|
|
|
|
2019-11-03 17:10:27 +00:00
|
|
|
var getter = function() {
|
|
|
|
return greenlock._config(flags);
|
|
|
|
};
|
|
|
|
if (flags.all) {
|
|
|
|
getter = function() {
|
|
|
|
return greenlock._configAll(flags);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return getter()
|
2019-11-03 01:33:12 +00:00
|
|
|
.catch(function(err) {
|
|
|
|
console.error();
|
|
|
|
console.error('error:', err.message);
|
2019-11-03 07:58:01 +00:00
|
|
|
//console.log(err.stack);
|
2019-11-03 01:33:12 +00:00
|
|
|
console.error();
|
2019-11-03 07:58:01 +00:00
|
|
|
process.exit(1);
|
2019-11-03 01:33:12 +00:00
|
|
|
})
|
2019-11-03 17:10:27 +00:00
|
|
|
.then(function(sites) {
|
|
|
|
if (!sites) {
|
2019-11-03 01:33:12 +00:00
|
|
|
console.info();
|
2019-11-03 17:10:27 +00:00
|
|
|
if (flags.all) {
|
|
|
|
console.info('No configs found');
|
|
|
|
} else {
|
|
|
|
console.info('No config found for', flags.servername);
|
|
|
|
}
|
2019-11-03 01:33:12 +00:00
|
|
|
console.info();
|
|
|
|
process.exit(1);
|
|
|
|
return;
|
|
|
|
}
|
2019-11-03 17:10:27 +00:00
|
|
|
if (!Array.isArray(sites)) {
|
|
|
|
sites = [sites];
|
|
|
|
}
|
2019-11-03 07:58:01 +00:00
|
|
|
|
2019-11-03 17:10:27 +00:00
|
|
|
sites.forEach(function(site) {
|
|
|
|
console.info();
|
|
|
|
console.info(
|
|
|
|
'Config for ' +
|
|
|
|
JSON.stringify(flags.servername || site.subject) +
|
|
|
|
':'
|
|
|
|
);
|
|
|
|
console.info(JSON.stringify(site, null, 2));
|
|
|
|
});
|
2019-11-03 01:33:12 +00:00
|
|
|
});
|
|
|
|
}
|