Skip to content

Commit

Permalink
Add STDIN Timeout, Change input STDIN check to '-i -'
Browse files Browse the repository at this point in the history
  • Loading branch information
camdenmoors committed Mar 15, 2022
1 parent 6ccf441 commit 1e73f5d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/utils/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'}),
}
Expand All @@ -35,9 +35,15 @@ export default abstract class BaseCommand extends Command {
const {flags} = this.parse(this.constructor as Input<typeof BaseCommand.flags>)
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) {
Expand Down

0 comments on commit 1e73f5d

Please sign in to comment.