Skip to content

Commit

Permalink
refactor(cli): display from topic & qos in sub
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfscream committed Feb 27, 2024
1 parent 1448e23 commit f84d4d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export class Commander {
parseUserProperties,
)
.option('-f, --format <TYPE>', 'format the message body, support base64, json, hex and cbor', parseFormat)
.option('-v, --verbose', 'print the topic before the message')
.option('-v, --verbose', 'Turn on verbose mode to display incoming MQTT packets')
.option(
'--output-mode <default/clean>',
'choose between the default and clean mode, which outputs the complete MQTT packet data, allowing users to pipe the output as they wish',
Expand Down
9 changes: 6 additions & 3 deletions cli/src/lib/sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,16 @@ const sub = (options: SubscribeOptions) => {

const msgData: Record<string, unknown>[] = []

options.verbose && msgData.push({ label: 'topic', value: topic })
options.verbose && msgData.push({ label: 'mqtt-packet', value: packet })

let receivedMessage = processReceivedMessage(payload, protobufPath, protobufMessageName, format)
msgData.push({ label: 'payload', value: receivedMessage })
msgData.push({ label: 'topic', value: topic })
msgData.push({ label: 'qos', value: packet.qos })

packet.retain && msgData.push({ label: 'retain', value: packet.retain })

let receivedMessage = processReceivedMessage(payload, protobufPath, protobufMessageName, format)
msgData.push({ label: 'payload', value: receivedMessage })

if (packet.properties?.userProperties) {
const up: { key: string; value: string }[] = []
Object.entries(packet.properties.userProperties).forEach(([key, value]) => {
Expand Down

0 comments on commit f84d4d2

Please sign in to comment.