Skip to content

Commit

Permalink
feat(cli): add support debug mode with
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfscream committed Dec 27, 2023
1 parent 72fe43c commit 4f27cfa
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class Commander {
'--config [PATH]',
'load the parameters from the local configuration file, which supports json and yaml format, default path is ./mqttx-cli-config.json',
)
.option('--debug', 'Enable debug mode for MQTT.js', false)
.allowUnknownOption(false)
.action(conn)

Expand Down Expand Up @@ -206,6 +207,7 @@ export class Commander {
'-Pmn, --protobuf-message-name <NAME>',
'the name of the protobuf message type (must exist in the .proto file)',
)
.option('--debug', 'Enable debug mode for MQTT.js', false)
.allowUnknownOption(false)
.action(pub)

Expand Down Expand Up @@ -304,6 +306,7 @@ export class Commander {
'-Pmn, --protobuf-message-name <NAME>',
'the name of the protobuf message type (must exist in the .proto file)',
)
.option('--debug', 'Enable debug mode for MQTT.js', false)
.allowUnknownOption(false)
.action(sub)

Expand Down
5 changes: 4 additions & 1 deletion cli/src/lib/conn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import { Signale, signale, basicLog, benchLog } from '../utils/signale'
import { parseConnectOptions } from '../utils/parse'
import delay from '../utils/delay'
import { saveConfig, loadConfig } from '../utils/config'
import * as Debug from 'debug'

const conn = (options: ConnectOptions) => {
const { save, config } = options
const { debug, save, config } = options

config && (options = loadConfig('conn', config))

save && saveConfig('conn', options)

debug && Debug.enable('mqttjs*')

const { maximumReconnectTimes } = options

const connOpts = parseConnectOptions(options, 'conn')
Expand Down
5 changes: 4 additions & 1 deletion cli/src/lib/pub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { saveConfig, loadConfig } from '../utils/config'
import { loadSimulator } from '../utils/simulate'
import { serializeProtobufToBuffer } from '../utils/protobuf'
import convertPayload from '../utils/convertPayload'
import * as Debug from 'debug'

const processPublishMessage = (
message: string | Buffer,
Expand Down Expand Up @@ -143,12 +144,14 @@ const multisend = (
}

const pub = (options: PublishOptions) => {
const { save, config } = options
const { debug, save, config } = options

config && (options = loadConfig('pub', config))

save && saveConfig('pub', options)

debug && Debug.enable('mqttjs*')

checkTopicExists(options.topic, 'pub')

const connOpts = parseConnectOptions(options, 'pub')
Expand Down
5 changes: 4 additions & 1 deletion cli/src/lib/sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import delay from '../utils/delay'
import convertPayload from '../utils/convertPayload'
import { saveConfig, loadConfig } from '../utils/config'
import { deserializeBufferToProtobuf } from '../utils/protobuf'
import * as Debug from 'debug'

const processReceivedMessage = (
payload: Buffer,
Expand Down Expand Up @@ -36,12 +37,14 @@ const processReceivedMessage = (
}

const sub = (options: SubscribeOptions) => {
const { save, config } = options
const { debug, save, config } = options

config && (options = loadConfig('sub', config))

save && saveConfig('sub', options)

debug && Debug.enable('mqttjs*')

checkTopicExists(options.topic, 'sub')

const connOpts = parseConnectOptions(options, 'sub')
Expand Down
1 change: 1 addition & 0 deletions cli/src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ declare global {
willUserProperties?: Record<string, string | string[]>
save?: boolean | string
config?: boolean | string
debug?: boolean
}

interface PublishOptions extends ConnectOptions {
Expand Down

0 comments on commit 4f27cfa

Please sign in to comment.