mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-19 08:02:55 +00:00
fix: repair and unify subcommand help outputs
This commit is contained in:
28
src/cli.ts
28
src/cli.ts
@@ -32,11 +32,15 @@ const pkgJson = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'))
|
||||
|
||||
const client = new HttpClient();
|
||||
const commander = new Command();
|
||||
|
||||
let actionDone = false;
|
||||
const helpAndExit = (help: string) => {
|
||||
// tslint:disable-next-line: no-console
|
||||
console.log(help);
|
||||
process.exit(-1);
|
||||
};
|
||||
|
||||
commander
|
||||
.command('e2e <to>')
|
||||
.version(pkgJson.version)
|
||||
.description('Run in end to end test mode. Indexing and afterwards retrieving all test files from @openstapp/core to the backend')
|
||||
.option('-s --samples [path]', 'Path to @openstapp/core test files', './node_modules/@openstapps/core/test/resources')
|
||||
.option('-w --waiton [resource]', 'wait-on resource parameter see "www.npmjs.com/wait-on"')
|
||||
@@ -47,12 +51,9 @@ commander
|
||||
toURL = (new URL(to)).toString();
|
||||
} catch (err) {
|
||||
await Logger.error('expected parameter <to> to be valid url', err);
|
||||
e2eCommand.outputHelp();
|
||||
process.exit(-1);
|
||||
helpAndExit(e2eCommand.helpInformation());
|
||||
}
|
||||
|
||||
actionDone = true;
|
||||
|
||||
try {
|
||||
if (typeof e2eCommand.waiton === 'string') {
|
||||
Logger.info(`Waiting for availibilty of resource: ${e2eCommand.waiton}`);
|
||||
@@ -87,8 +88,8 @@ commander
|
||||
// validate type
|
||||
if (typeof type !== 'string') {
|
||||
await Logger.error('expected parameter "type" to be of type: string');
|
||||
copyCommand.outputHelp();
|
||||
process.exit(-1);
|
||||
copyCommand.help();
|
||||
helpAndExit(copyCommand.helpInformation());
|
||||
}
|
||||
|
||||
let fromURL = '';
|
||||
@@ -100,19 +101,15 @@ commander
|
||||
toURL = (new URL(to)).toString();
|
||||
} catch (err) {
|
||||
await Logger.error('expected parameters "from" and "to" to be valid urls', err);
|
||||
copyCommand.outputHelp();
|
||||
process.exit(-1);
|
||||
helpAndExit(copyCommand.helpInformation());
|
||||
}
|
||||
|
||||
// validate batchSize
|
||||
if (isNaN(parseInt(batchSize, 10))) {
|
||||
await Logger.error('expected parameter "batchSize" to be of type: number');
|
||||
copyCommand.outputHelp();
|
||||
process.exit(-1);
|
||||
helpAndExit(copyCommand.helpInformation());
|
||||
}
|
||||
|
||||
actionDone = true;
|
||||
|
||||
Logger.info(`Copying ${type} objects from ${fromURL} to ${toURL}`);
|
||||
|
||||
copy(client, {
|
||||
@@ -133,6 +130,3 @@ commander
|
||||
commander
|
||||
.parse(process.argv);
|
||||
|
||||
if (!actionDone) {
|
||||
commander.outputHelp();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user