From 9e61ea81c4d6b30ec72d4f9687c4a5be91f99f3c Mon Sep 17 00:00:00 2001 From: YuShifan <894402575bt@gmail.com> Date: Mon, 2 Sep 2024 16:14:48 +0800 Subject: [PATCH] fix(cli): mqtt version 5 -> 5.0 --- cli/README-CN.md | 6 +++--- cli/src/index.ts | 14 +++++++------- cli/src/utils/parse.ts | 8 +++++--- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/cli/README-CN.md b/cli/README-CN.md index 5fa9240a6..e74eb6b60 100644 --- a/cli/README-CN.md +++ b/cli/README-CN.md @@ -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 | MQTT Broker 的 Host 地址,默认为 localhost | | -p, --port | MQTT Broker 的端口号 | | -i, --client-id | 客户端 ID | @@ -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 | MQTT Broker 的 Host 地址,默认为 localhost | | -p, --port | MQTT Broker 的端口号 | | -i, --client-id | 客户端 ID | @@ -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 | MQTT Broker 的 Host 地址,默认为 localhost | | -p, --port | MQTT Broker 的端口号 | | -i, --client-id | 客户端 ID | diff --git a/cli/src/index.ts b/cli/src/index.ts index 789941abb..0b1c55e39 100755 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -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 ', 'the broker host', state.getConfig('host')) .option('-p, --port ', 'the broker port', parseNumber, state.getConfig('port')) .option('-i, --client-id ', 'the client id', getClientId()) @@ -161,7 +161,7 @@ export class Commander { .option('-si, --subscription-identifier ', 'the identifier of the subscription', parseNumber) .option('-ct, --content-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 ', 'the broker host', state.getConfig('host')) .option('-p, --port ', 'the broker port', parseNumber, state.getConfig('port')) .option( @@ -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 ', 'the broker host', state.getConfig('host')) .option('-p, --port ', 'the broker port', parseNumber, state.getConfig('port')) .option('-i, --client-id ', 'the client id', getClientId()) @@ -388,7 +388,7 @@ export class Commander { .description('Create a custom number of connections.') .option('-c, --count ', 'the number of connections', parseNumber, 1000) .option('-i, --interval ', '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 ', 'the broker host', state.getConfig('host')) .option('-p, --port ', 'the broker port', parseNumber, state.getConfig('port')) .option('-I, --client-id ', 'the client id, support %i (index) variable', getClientId()) @@ -504,7 +504,7 @@ export class Commander { .option('-ct, --content-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 ', 'the broker host', state.getConfig('host')) .option('-p, --port ', 'the broker port', parseNumber, state.getConfig('port')) .option('-I, --client-id ', 'the client id, support %i (index) variable', getClientId()) @@ -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 ', 'the broker host', state.getConfig('host')) .option('-p, --port ', 'the broker port', parseNumber, state.getConfig('port')) .option('-I, --client-id ', 'the client id, support %i (index) variable', getClientId()) @@ -726,7 +726,7 @@ export class Commander { .option('-ct, --content-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 ', 'the broker host', state.getConfig('host')) .option('-p, --port ', 'the broker port', parseNumber, state.getConfig('port')) .option('-I, --client-id ', 'the client id, support %i (index) variable', getClientId()) diff --git a/cli/src/utils/parse.ts b/cli/src/utils/parse.ts index f37fefd9d..db635de7b 100644 --- a/cli/src/utils/parse.ts +++ b/cli/src/utils/parse.ts @@ -26,16 +26,18 @@ const parseProtocol = (value: string) => { } const parseMQTTVersion = (value: string) => { - const dict = { + const dict: Record = { '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) => {