@e-invoice-eu/cli
Version:
Generate e-invoices (E-Rechnung in German) conforming to EN16931 (Factur-X/ZUGFeRD, UBL, CII, XRechnung aka X-Rechnung) from LibreOffice Calc/Excel data or JSON.
82 lines • 2.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Format = void 0;
const core_1 = require("@e-invoice-eu/core");
const runtime_1 = require("@esgettext/runtime");
const optspec_1 = require("../optspec");
const package_1 = require("../package");
const gtx = runtime_1.Textdomain.getInstance('e-invoice-eu-cli');
const options = {
list: {
group: gtx._('Operation mode'),
alias: ['l'],
type: 'boolean',
conflicts: 'info',
demandOption: false,
describe: gtx._('list all supported formats'),
},
info: {
group: gtx._('Operation mode'),
alias: ['i'],
type: 'string',
conflicts: 'list',
demandOption: false,
describe: gtx._('show detailed information about one format'),
},
};
class Format {
description() {
return gtx._('List and describe supported formats.');
}
aliases() {
return [];
}
build(argv) {
return argv.options(options);
}
list() {
const factoryService = new core_1.FormatFactoryService();
const formats = factoryService
.listFormatServices()
.map(format => format.name)
.join('\n');
console.log(formats);
}
info(format) {
const factoryService = new core_1.FormatFactoryService();
const info = factoryService.info(format);
for (const prop in info) {
console.log(`${prop}: ${info[prop]}`);
}
}
async doRun(configOptions) {
if (typeof configOptions.info === 'undefined' && !configOptions.list) {
throw new Error(gtx._("One of the options '--list' or '--info' is required!"));
}
if (configOptions.list) {
this.list();
}
else {
this.info(configOptions.info);
}
}
async run(argv) {
const configOptions = argv;
if (!(0, optspec_1.coerceOptions)(argv, options)) {
return 1;
}
try {
await this.doRun(configOptions);
return 0;
}
catch (e) {
console.error(gtx._x('{programName}: {error}', {
programName: package_1.Package.getName(),
error: e,
}));
return 1;
}
}
}
exports.Format = Format;
//# sourceMappingURL=format.js.map