Skip to content

Commit 7fe98bc

Browse files
committed
Pretty indent --info JSON output (see below for details)
Changes to make --info much more human readable (while still keeping machine readabilty for anyone foolish enough to be parsing the existing output as text) * change message_to_json to optionally not strip the multiline JSON * use multiline=True for the two places we are printing to the console * make the node list JSON indented
1 parent 2f9307f commit 7fe98bc

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

meshtastic/mesh_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def showInfo(self, file=sys.stdout) -> str: # pylint: disable=W0613
133133
# use id as dictionary key for correct json format in list of nodes
134134
nodeid = n2["user"]["id"]
135135
nodes[nodeid] = n2
136-
infos = owner + myinfo + metadata + mesh + json.dumps(nodes)
136+
infos = owner + myinfo + metadata + mesh + json.dumps(nodes, indent=2)
137137
print(infos)
138138
return infos
139139

meshtastic/node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ def showInfo(self):
6464
"""Show human readable description of our node"""
6565
prefs = ""
6666
if self.localConfig:
67-
prefs = message_to_json(self.localConfig)
67+
prefs = message_to_json(self.localConfig, multiline=True)
6868
print(f"Preferences: {prefs}\n")
6969
prefs = ""
7070
if self.moduleConfig:
71-
prefs = message_to_json(self.moduleConfig)
71+
prefs = message_to_json(self.moduleConfig, multiline=True)
7272
print(f"Module preferences: {prefs}\n")
7373
self.showChannels()
7474

meshtastic/util.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@ def check_if_newer_version():
627627

628628
return pypi_version
629629

630-
def message_to_json(message):
631-
"Return protobuf message as JSON. Always print all fields, even when not present in data."
632-
return stripnl(MessageToJson(message, always_print_fields_with_no_presence=True))
630+
631+
def message_to_json(message, multiline=False):
632+
"""Return protobuf message as JSON. Always print all fields, even when not present in data."""
633+
json = MessageToJson(message, always_print_fields_with_no_presence=True)
634+
return stripnl(json) if not multiline else json

0 commit comments

Comments
 (0)