diff --git a/src/commands/tail-cloudwatch-logs.js b/src/commands/tail-cloudwatch-logs.js index a1b6c01..cec02e1 100644 --- a/src/commands/tail-cloudwatch-logs.js +++ b/src/commands/tail-cloudwatch-logs.js @@ -32,7 +32,7 @@ class TailCloudwatchLogsCommand extends Command { const logGroupName = await this.getLogGroupName(namePrefix); this.log(`polling CLoudWatch log group [${logGroupName}]...`); - this.log("press to stop"); + this.log("press ctrl+C to stop"); await this.pollLogGroup(logGroupName); this.exit(0); @@ -94,9 +94,11 @@ class TailCloudwatchLogsCommand extends Command { readline.emitKeypressEvents(process.stdin); process.stdin.setRawMode(true); const stdin = process.openStdin(); - stdin.once("keypress", () => { - polling = false; - this.log("stopping..."); + stdin.on("keypress", async (data, key) => { + if (key && key.ctrl && key.name == "c") { + polling = false; + this.log("stopping..."); + } }); const fetch = async (startTime, endTime, nextToken, acc = []) => { diff --git a/src/commands/tail-dynamodb.js b/src/commands/tail-dynamodb.js index ba58863..378fcbf 100644 --- a/src/commands/tail-dynamodb.js +++ b/src/commands/tail-dynamodb.js @@ -34,7 +34,7 @@ class TailDynamodbCommand extends Command { this.log( `polling DynamoDB stream for table [${tableName}] (${stream.shardIds.length} shards)...` ); - this.log("press to stop"); + this.log("press ctrl-C to stop"); await this.pollDynamoDBStreams(streamArn, stream.shardIds); this.exit(0); @@ -91,9 +91,11 @@ class TailDynamodbCommand extends Command { readline.emitKeypressEvents(process.stdin); process.stdin.setRawMode(true); const stdin = process.openStdin(); - stdin.once("keypress", () => { - polling = false; - this.log("stopping..."); + stdin.on("keypress", async (data, key) => { + if (key && key.ctrl && key.name == "c") { + polling = false; + this.log("stopping..."); + } }); const promises = shardIds.map(async shardId => { diff --git a/src/commands/tail-eventbridge-rule.js b/src/commands/tail-eventbridge-rule.js index ac1e3a4..1a34493 100644 --- a/src/commands/tail-eventbridge-rule.js +++ b/src/commands/tail-eventbridge-rule.js @@ -138,19 +138,20 @@ class TailEventbridgeRuleCommand extends Command { await this.addTarget(queueArn); this.log(`polling event rule [${ruleArn}]...`); - this.log("press to stop"); + this.log("press ctrl-C to stop"); let polling = true; const readline = require("readline"); readline.emitKeypressEvents(process.stdin); process.stdin.setRawMode(true); const stdin = process.openStdin(); - stdin.once("keypress", async () => { - polling = false; - this.log("stopping..."); - - await this.removeTarget(); - await this.deleteQueue(queueUrl); + stdin.on("keypress", async (data, key) => { + if (key && key.ctrl && key.name == "c") { + this.log("stopping..."); + polling = false; + await this.removeTarget(); + await this.deleteQueue(queueUrl); + } }); const AWS = getAWSSDK(); diff --git a/src/commands/tail-kinesis.js b/src/commands/tail-kinesis.js index 6533943..d111032 100644 --- a/src/commands/tail-kinesis.js +++ b/src/commands/tail-kinesis.js @@ -25,7 +25,7 @@ class TailKinesisCommand extends Command { this.log( `polling Kinesis stream [${streamName}] (${stream.shardIds.length} shards)...` ); - this.log("press to stop"); + this.log("press ctrl-C to stop"); await this.pollKinesis(streamName, stream.shardIds); } @@ -63,9 +63,11 @@ class TailKinesisCommand extends Command { readline.emitKeypressEvents(process.stdin); process.stdin.setRawMode(true); const stdin = process.openStdin(); - stdin.once("keypress", () => { - polling = false; - this.log("stopping..."); + stdin.on("keypress", async (data, key) => { + if (key && key.ctrl && key.name == "c") { + polling = false; + this.log("stopping..."); + } }); const promises = shardIds.map(async shardId => { diff --git a/src/commands/tail-sns.js b/src/commands/tail-sns.js index 39cf80e..a78fe25 100644 --- a/src/commands/tail-sns.js +++ b/src/commands/tail-sns.js @@ -85,19 +85,21 @@ class TailSnsCommand extends Command { const subscriptionArn = await this.subscribeToSNS(topicArn, queueArn); this.log(`polling SNS topic [${topicArn}]...`); - this.log("press to stop"); + this.log("press ctrl-C to stop"); let polling = true; const readline = require("readline"); readline.emitKeypressEvents(process.stdin); process.stdin.setRawMode(true); const stdin = process.openStdin(); - stdin.once("keypress", async () => { - polling = false; - this.log("stopping..."); + stdin.on("keypress", async (data, key) => { + if (key && key.ctrl && key.name == "c") { + polling = false; + this.log("stopping..."); - await this.unsubscribeFromSNS(subscriptionArn); - await this.deleteQueue(queueUrl); + await this.unsubscribeFromSNS(subscriptionArn); + await this.deleteQueue(queueUrl); + } }); const AWS = getAWSSDK(); diff --git a/src/commands/tail-sqs.js b/src/commands/tail-sqs.js index b239d7b..ac0ec02 100644 --- a/src/commands/tail-sqs.js +++ b/src/commands/tail-sqs.js @@ -25,7 +25,7 @@ class TailSqsCommand extends Command { const queueUrl = await getQueueUrl(queueName); this.log(`polling SQS queue [${queueUrl}]...`); - this.log("press to stop"); + this.log("press ctrl-C to stop"); await this.pollSqs(queueUrl); this.exit(0); @@ -40,10 +40,12 @@ class TailSqsCommand extends Command { readline.emitKeypressEvents(process.stdin); process.stdin.setRawMode(true); const stdin = process.openStdin(); - stdin.once("keypress", () => { - polling = false; - this.log("stopping..."); - seenMessageIds = new Set(); + stdin.on("keypress", async (data, key) => { + if (key && key.ctrl && key.name == "c") { + polling = false; + this.log("stopping..."); + seenMessageIds = new Set(); + } }); // eslint-disable-next-line no-constant-condition