diff --git a/src/export.js b/src/export.js index 296fd21..440cda2 100644 --- a/src/export.js +++ b/src/export.js @@ -42,6 +42,12 @@ exports.builder = { description: 'Which index(es) to fetch', type: 'array', default: [] + }, + outputFile: { + alias: 'o', + description: 'Output file name(s)', + type: 'array', + default: [] } } @@ -49,15 +55,34 @@ exports.handler = async function (options) { const client = await getClient(options) console.time('Export') - return client - .export(options.format, [...options.entities, ...options.index], options.outputFile) - .then(entities => { - console.timeEnd('Export') - for (const { status, reason } of entities) { - if (status === 'rejected') { - console.error(reason) - } - } + const tasks = [] + const targets = [...options.entities, ...options.index] + if (targets.length !== options.outputFile.length) { + console.error('The number of entities and output files must match.') + process.exit(1) + } + + for (let i = 0; i < targets.length; i++) { + tasks.push( + client + .export(options.format, [targets[i]], options.outputFile[i]) + .then(entities => { + for (const { status, reason } of entities) { + if (status === 'rejected') { + console.error(reason) + } + } + }) + ) + } + + return Promise.all(tasks) + .then(() => { + console.timeEnd('Export') + }) + .catch(err => { + console.error('Error during export:', err) + console.timeEnd('Export') }) }