From 1e73f5dab9b897948898bb79012e25c26be77a7e Mon Sep 17 00:00:00 2001 From: Camden Moors Date: Tue, 15 Mar 2022 15:41:32 -0400 Subject: [PATCH] Add STDIN Timeout, Change input STDIN check to '-i -' --- src/utils/base-command.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/utils/base-command.ts b/src/utils/base-command.ts index 3c9b45521..20cb69477 100644 --- a/src/utils/base-command.ts +++ b/src/utils/base-command.ts @@ -18,8 +18,8 @@ export function omitFlags(flagsToOmit: string[]): typeof BaseCommand.flags { export default abstract class BaseCommand extends Command { static flags = { help: flags.help({char: 'h'}), - input: flags.string({char: 'i', required: false, description: 'Input file to be converted'}), - output: flags.string({char: 'o', required: false}), + input: flags.string({char: 'i', required: true, description: 'Input file to be converted'}), + output: flags.string({char: 'o', required: true}), logLevel: flags.string({char: 'L', required: false, default: 'info', options: ['info', 'warn', 'debug', 'verbose']}), listAllCommands: flags.boolean({char: 'A', required: false, description: 'List all SAF CLI commands'}), } @@ -35,9 +35,15 @@ export default abstract class BaseCommand extends Command { const {flags} = this.parse(this.constructor as Input) this.parsedFlags = flags this.logger = createWinstonLogger(this.constructor.name, flags.logLevel as unknown as string) - - if (!flags.input) { - BaseCommand.inputFileData = await read(process.stdin, this.logger) + if (this.parsedFlags.input === '-') { + await new Promise((resolve, reject) => { + setTimeout(() => reject(new Error('STDIN Timeout')), 5000) + + read(process.stdin, this.logger).then(data => { + BaseCommand.inputFileData = data + resolve(data) + }) + }) } if (flags.listAllCommands) {