Skip to content

Commit

Permalink
feat(cli): add exit tips for conn
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfscream authored and Red-Asuka committed Dec 3, 2024
1 parent 72c4341 commit dcd8435
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cli/src/lib/conn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { parseConnectOptions } from '../utils/parse'
import delay from '../utils/delay'
import { handleSaveOptions, handleLoadOptions } from '../utils/options'
import * as Debug from 'debug'
import { triggerExitInfo } from '../utils/exitInfo'

const conn = (options: ConnectOptions) => {
const { debug, saveOptions, loadOptions } = options
Expand All @@ -27,6 +28,7 @@ const conn = (options: ConnectOptions) => {
client.on('connect', () => {
basicLog.connected()
retryTimes = 0
setTimeout(triggerExitInfo, 1000)
})

client.on('error', (err) => {
Expand Down Expand Up @@ -96,6 +98,7 @@ const benchConn = async (options: BenchConnectOptions) => {
if (connectedCount === count) {
const end = Date.now()
signale.success(`Created ${count} connections in ${(end - start) / 1000}s`)
setTimeout(triggerExitInfo, 1000)
}
} else {
benchLog.reconnected(connectedCount, count, opts.clientId!)
Expand Down
2 changes: 2 additions & 0 deletions cli/src/lib/pub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { checkScenarioExists, checkTopicExists, parseConnectOptions, parsePublis
import { serializeProtobufToBuffer } from '../utils/protobuf'
import { serializeAvroToBuffer } from '../utils/avro'
import { loadSimulator } from '../utils/simulate'
import { triggerExitInfo } from '../utils/exitInfo'

/**
* Processes the outgoing message through two potential stages:
Expand Down Expand Up @@ -154,6 +155,7 @@ const multiSend = (

client.on('connect', () => {
basicLog.enterToPublish()
setTimeout(triggerExitInfo, 1000)
retryTimes = 0
isNewConnection &&
pump(process.stdin, split2(), sender, (err) => {
Expand Down
5 changes: 5 additions & 0 deletions cli/src/utils/exitInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import chalk from 'chalk'

export const triggerExitInfo = () => {
console.log(chalk.dim('- Press Ctrl+C to disconnect and exit'))
}
2 changes: 1 addition & 1 deletion cli/src/utils/logWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const basicLog = {
},
publishing: () => logWrapper.await('Message publishing...'),
published: () => logWrapper.success('Message published'),
enterToPublish: () => logWrapper.success('Connected, press Enter to publish, press Ctrl+C to exit'),
enterToPublish: () => logWrapper.success('Connected, input and press Enter to publish'),
error: (err: Error) => logWrapper.fail(err.toString()),
close: () => logWrapper.fail('Connection closed'),
reconnecting: (retryTimes: number, maxReTryTimes: number) =>
Expand Down

0 comments on commit dcd8435

Please sign in to comment.