Skip to content

Commit

Permalink
chore(cli): set default client id
Browse files Browse the repository at this point in the history
  • Loading branch information
Red-Asuka committed Jun 29, 2022
1 parent 050f8ea commit d7b3594
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
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 }

0 comments on commit d7b3594

Please sign in to comment.