Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add exit tips for conn #1821

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'))
Red-Asuka marked this conversation as resolved.
Show resolved Hide resolved
}
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