feat: add api

This commit is contained in:
Karl-Philipp Wulfert
2018-11-29 17:38:57 +01:00
commit 4839f941c6
27 changed files with 7111 additions and 0 deletions

77
src/cli.ts Executable file
View File

@@ -0,0 +1,77 @@
/*
* Copyright (C) 2018 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Logger} from '@openstapps/logger';
import * as commander from 'commander';
import {readFileSync} from 'fs';
import {join} from 'path';
import {copy} from './copy';
import {HttpClient} from './httpClient';
const logger = new Logger();
const pkgJson = JSON.parse(readFileSync(join(__dirname, '..', 'package.json')).toString());
const client = new HttpClient();
let actionDone = false;
process.on('unhandledRejection', (error) => {
logger.error('unhandledRejection', error);
});
commander
.command('copy <from> <to>')
.version(pkgJson.version)
.description('Copy data from one instance to another')
.option(
'-s, --bulkSource [bulkSource]',
'The source identifier for the bulk to use with the target instance [copy]',
'copy',
)
.option('-t, --type <type>', 'The type to request from the source instance')
// TODO: remove
.option('-a, --appVersion [version]', 'The App version to use [unset by default]')
.option('-b, --batchSize <amount>', 'Number of items per batch')
.allowUnknownOption(false)
.action((from, to, copyCommand) => {
actionDone = true;
if (typeof copyCommand.type === 'undefined') {
logger.error('<type> argument is required');
copyCommand.outputHelp();
process.exit(-1);
}
logger.info('Copying ' + copyCommand.type + ' objects from ' + from + ' to ' + to);
copy(client, {
batchSize: parseInt(copyCommand.batchSize, 10),
from: from,
source: copyCommand.bulkSource,
to: to,
type: copyCommand.type,
version: copyCommand.appVersion,
}).then(() => {
logger.ok('Done');
}, (err) => {
throw err;
});
});
commander
.parse(process.argv);
if (!actionDone) {
commander.outputHelp();
}