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

chore(cli): set default client id #975

Merged
merged 1 commit into from
Jun 29, 2022
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
5 changes: 3 additions & 2 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Command } from 'commander'
import { getClientId } from './utils/generator'
import { parseNumber, parseProtocol } from './utils/parse'
import pub from './lib/pub'
import sub from './lib/sub'
Expand All @@ -19,7 +20,7 @@ export class Commander {
.description('Publish a message to a topic.')
.option('-h, --hostname <HOST>', 'the broker host')
.option('-p, --port <PORT>', 'the broker port', parseNumber)
.option('-i, --client-id <ID>', 'the client id')
.option('-i, --client-id <ID>', 'the client id', getClientId())
.option('-q, --qos <0/1/2>', 'the QoS of the message', parseNumber, 0)
.requiredOption('-t, --topic <TOPIC>', 'the message topic')
.option('-m, --message <MSG>', 'the message body', 'Hello From MQTT X CLI')
Expand All @@ -44,7 +45,7 @@ export class Commander {
.description('Subscribes to a topic.')
.option('-h, --hostname <HOST>', 'the broker host', 'localhost')
.option('-p, --port <PORT>', 'the broker port', parseNumber)
.option('-i, --client-id <ID>', 'the client id')
.option('-i, --client-id <ID>', 'the client id', getClientId())
.option('-q, --qos <0/1/2>', 'the QoS of the message', parseNumber, 0)
.option('--clean', 'discard any pending message for the given id', true)
.requiredOption('-t, --topic <TOPIC>', 'the message topic')
Expand Down
3 changes: 3 additions & 0 deletions cli/src/utils/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const getClientId = () => `mqttx_${Math.random().toString(16).substring(2, 10)}`

export { getClientId }