fix: repair and unify subcommand help outputs

This commit is contained in:
Rainer Killinger
2020-03-02 15:05:33 +01:00
parent e18858fc58
commit 4ae968ff0f
4 changed files with 151 additions and 104 deletions

View File

@@ -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();
}