mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 00:52:55 +00:00
42
src/cli.ts
42
src/cli.ts
@@ -16,6 +16,7 @@ import {Logger} from '@openstapps/logger';
|
|||||||
import * as commander from 'commander';
|
import * as commander from 'commander';
|
||||||
import {readFileSync} from 'fs';
|
import {readFileSync} from 'fs';
|
||||||
import {join} from 'path';
|
import {join} from 'path';
|
||||||
|
import { URL } from 'url';
|
||||||
import {copy} from './copy';
|
import {copy} from './copy';
|
||||||
import {HttpClient} from './httpClient';
|
import {HttpClient} from './httpClient';
|
||||||
|
|
||||||
@@ -31,36 +32,53 @@ process.on('unhandledRejection', (error) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
commander
|
commander
|
||||||
.command('copy <from> <to>')
|
.command('copy <type> <from> <to> <batchSize>')
|
||||||
.version(pkgJson.version)
|
.version(pkgJson.version)
|
||||||
.description('Copy data from one instance to another')
|
.description('Copy data from one instance to another')
|
||||||
.option(
|
.option(
|
||||||
'-s, --bulkSource [bulkSource]',
|
'-s, --bulkSource <bulkSource>',
|
||||||
'The source identifier for the bulk to use with the target instance [copy]',
|
'The source identifier for the bulk to use with the target instance [copy]',
|
||||||
'copy',
|
'copy',
|
||||||
)
|
)
|
||||||
.option('-t, --type <type>', 'The type to request from the source instance')
|
|
||||||
// TODO: remove
|
// TODO: remove
|
||||||
.option('-a, --appVersion [version]', 'The App version to use [unset by default]')
|
.option('-a, --appVersion <version>', 'The App version to use [unset by default]')
|
||||||
.option('-b, --batchSize <amount>', 'Number of items per batch')
|
|
||||||
.allowUnknownOption(false)
|
.allowUnknownOption(false)
|
||||||
.action((from, to, copyCommand) => {
|
.action((type, from, to, batchSize, copyCommand) => {
|
||||||
actionDone = true;
|
|
||||||
|
|
||||||
if (typeof copyCommand.type === 'undefined') {
|
// validate type
|
||||||
logger.error('<type> argument is required');
|
if (typeof type !== 'string') {
|
||||||
|
logger.error('expected parameter "type" to be of type: string');
|
||||||
copyCommand.outputHelp();
|
copyCommand.outputHelp();
|
||||||
process.exit(-1);
|
process.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info('Copying ' + copyCommand.type + ' objects from ' + from + ' to ' + to);
|
// validate urls
|
||||||
|
try {
|
||||||
|
from = (new URL(from)).toString();
|
||||||
|
to = (new URL(to)).toString();
|
||||||
|
} catch (err) {
|
||||||
|
logger.error('expected parameters "from" and "to" to be valid urls', err);
|
||||||
|
copyCommand.outputHelp();
|
||||||
|
process.exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate batchSize
|
||||||
|
if (isNaN(parseInt(batchSize, 10))) {
|
||||||
|
logger.error('expected parameter "batchSize" to be of type: number');
|
||||||
|
copyCommand.outputHelp();
|
||||||
|
process.exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
actionDone = true;
|
||||||
|
|
||||||
|
logger.info('Copying ' + type + ' objects from ' + from + ' to ' + to);
|
||||||
|
|
||||||
copy(client, {
|
copy(client, {
|
||||||
batchSize: parseInt(copyCommand.batchSize, 10),
|
batchSize: parseInt(batchSize, 10),
|
||||||
from: from,
|
from: from,
|
||||||
source: copyCommand.bulkSource,
|
source: copyCommand.bulkSource,
|
||||||
to: to,
|
to: to,
|
||||||
type: copyCommand.type,
|
type: type,
|
||||||
version: copyCommand.appVersion,
|
version: copyCommand.appVersion,
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
logger.ok('Done');
|
logger.ok('Done');
|
||||||
|
|||||||
Reference in New Issue
Block a user