Skip to content

Commit

Permalink
fix(cli): mqtt version 5 -> 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfscream committed Sep 2, 2024
1 parent 3e67f6e commit 9e61ea8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions cli/README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ mqttx conn --help

| 参数 | 描述 |
| ------------------------------------------------ | ------------------------------------------------------------------------------------------ |
| -V, --mqtt-version <5/3.1.1/3.1> | MQTT 版本,默认为 5 |
| -V, --mqtt-version <5.0/3.1.1/3.1> | MQTT 版本,默认为 5 |
| -h, --hostname <HOST> | MQTT Broker 的 Host 地址,默认为 localhost |
| -p, --port <PORT> | MQTT Broker 的端口号 |
| -i, --client-id <ID> | 客户端 ID |
Expand Down Expand Up @@ -226,7 +226,7 @@ mqttx sub --help

| 参数 | 描述 |
| ------------------------------------------------ | ------------------------------------------------------------------------------------------ |
| -V, --mqtt-version <5/3.1.1/3.1> | MQTT 版本,默认为 5 |
| -V, --mqtt-version <5.0/3.1.1/3.1> | MQTT 版本,默认为 5 |
| -h, --hostname <HOST> | MQTT Broker 的 Host 地址,默认为 localhost |
| -p, --port <PORT> | MQTT Broker 的端口号 |
| -i, --client-id <ID> | 客户端 ID |
Expand Down Expand Up @@ -284,7 +284,7 @@ mqttx pub --help

| 参数 | 描述 |
| ------------------------------------------------ | ------------------------------------------------------------------------------------------ |
| -V, --mqtt-version <5/3.1.1/3.1> | MQTT 版本,默认为 5 |
| -V, --mqtt-version <5.0/3.1.1/3.1> | MQTT 版本,默认为 5 |
| -h, --hostname <HOST> | MQTT Broker 的 Host 地址,默认为 localhost |
| -p, --port <PORT> | MQTT Broker 的端口号 |
| -i, --client-id <ID> | 客户端 ID |
Expand Down
14 changes: 7 additions & 7 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class Commander {
this.program
.command('conn')
.description('Create a connection and connect to MQTT Broker.')
.option('-V, --mqtt-version <5/3.1.1/3.1>', 'the MQTT version', parseMQTTVersion, 5)
.option('-V, --mqtt-version <5.0/3.1.1/3.1>', 'the MQTT version', parseMQTTVersion, 5)
.option('-h, --hostname <HOST>', 'the broker host', state.getConfig('host'))
.option('-p, --port <PORT>', 'the broker port', parseNumber, state.getConfig('port'))
.option('-i, --client-id <ID>', 'the client id', getClientId())
Expand Down Expand Up @@ -161,7 +161,7 @@ export class Commander {
.option('-si, --subscription-identifier <NUMBER>', 'the identifier of the subscription', parseNumber)
.option('-ct, --content-type <TYPE>', 'a description of the content of the publish message')
// connect options
.option('-V, --mqtt-version <5/3.1.1/3.1>', 'the MQTT version', parseMQTTVersion, 5)
.option('-V, --mqtt-version <5.0/3.1.1/3.1>', 'the MQTT version', parseMQTTVersion, 5)
.option('-h, --hostname <HOST>', 'the broker host', state.getConfig('host'))
.option('-p, --port <PORT>', 'the broker port', parseNumber, state.getConfig('port'))
.option(
Expand Down Expand Up @@ -282,7 +282,7 @@ export class Commander {
'default',
)
// connect options
.option('-V, --mqtt-version <5/3.1.1/3.1>', 'the MQTT version', parseMQTTVersion, 5)
.option('-V, --mqtt-version <5.0/3.1.1/3.1>', 'the MQTT version', parseMQTTVersion, 5)
.option('-h, --hostname <HOST>', 'the broker host', state.getConfig('host'))
.option('-p, --port <PORT>', 'the broker port', parseNumber, state.getConfig('port'))
.option('-i, --client-id <ID>', 'the client id', getClientId())
Expand Down Expand Up @@ -388,7 +388,7 @@ export class Commander {
.description('Create a custom number of connections.')
.option('-c, --count <NUMBER>', 'the number of connections', parseNumber, 1000)
.option('-i, --interval <MILLISECONDS>', 'interval of connecting to the broker', parseNumber, 10)
.option('-V, --mqtt-version <5/3.1.1/3.1>', 'the MQTT version', parseMQTTVersion, 5)
.option('-V, --mqtt-version <5.0/3.1.1/3.1>', 'the MQTT version', parseMQTTVersion, 5)
.option('-h, --hostname <HOST>', 'the broker host', state.getConfig('host'))
.option('-p, --port <PORT>', 'the broker port', parseNumber, state.getConfig('port'))
.option('-I, --client-id <ID>', 'the client id, support %i (index) variable', getClientId())
Expand Down Expand Up @@ -504,7 +504,7 @@ export class Commander {
.option('-ct, --content-type <TYPE>', 'a description of the content of the publish message')
.option('-v, --verbose', 'print history published total and message rate')
// connect options
.option('-V, --mqtt-version <5/3.1.1/3.1>', 'the MQTT version', parseMQTTVersion, 5)
.option('-V, --mqtt-version <5.0/3.1.1/3.1>', 'the MQTT version', parseMQTTVersion, 5)
.option('-h, --hostname <HOST>', 'the broker host', state.getConfig('host'))
.option('-p, --port <PORT>', 'the broker port', parseNumber, state.getConfig('port'))
.option('-I, --client-id <ID>', 'the client id, support %i (index) variable', getClientId())
Expand Down Expand Up @@ -608,7 +608,7 @@ export class Commander {
)
.option('-v, --verbose', 'print history received messages and rate')
// connect options
.option('-V, --mqtt-version <5/3.1.1/3.1>', 'the MQTT version', parseMQTTVersion, 5)
.option('-V, --mqtt-version <5.0/3.1.1/3.1>', 'the MQTT version', parseMQTTVersion, 5)
.option('-h, --hostname <HOST>', 'the broker host', state.getConfig('host'))
.option('-p, --port <PORT>', 'the broker port', parseNumber, state.getConfig('port'))
.option('-I, --client-id <ID>', 'the client id, support %i (index) variable', getClientId())
Expand Down Expand Up @@ -726,7 +726,7 @@ export class Commander {
.option('-ct, --content-type <TYPE>', 'a description of the content of the publish message')
.option('-v, --verbose', 'print history published total and message rate')
// connect options
.option('-V, --mqtt-version <5/3.1.1/3.1>', 'the MQTT version', parseMQTTVersion, 5)
.option('-V, --mqtt-version <5.0/3.1.1/3.1>', 'the MQTT version', parseMQTTVersion, 5)
.option('-h, --hostname <HOST>', 'the broker host', state.getConfig('host'))
.option('-p, --port <PORT>', 'the broker port', parseNumber, state.getConfig('port'))
.option('-I, --client-id <ID>', 'the client id, support %i (index) variable', getClientId())
Expand Down
8 changes: 5 additions & 3 deletions cli/src/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ const parseProtocol = (value: string) => {
}

const parseMQTTVersion = (value: string) => {
const dict = {
const dict: Record<string, number> = {
'3.1': 3,
'3.1.1': 4,
'5': 5,
}
if (!Object.keys(dict).includes(value)) {
// Normalize '5.0' to '5'
const normalizedValue = value === '5.0' ? '5' : value
if (!dict[normalizedValue]) {
logWrapper.fail('Not a valid MQTT version.')
process.exit(1)
}
return dict[value as '3.1' | '3.1.1' | '5']
return dict[normalizedValue as '3.1' | '3.1.1' | '5']
}

const parseKeyValues = (value: string, previous?: Record<string, string | string[]>) => {
Expand Down

0 comments on commit 9e61ea8

Please sign in to comment.