Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretty indent --info JSON output (see below for details) #558

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion meshtastic/mesh_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def showInfo(self, file=sys.stdout) -> str: # pylint: disable=W0613
# use id as dictionary key for correct json format in list of nodes
nodeid = n2["user"]["id"]
nodes[nodeid] = n2
infos = owner + myinfo + metadata + mesh + json.dumps(nodes)
infos = owner + myinfo + metadata + mesh + json.dumps(nodes, indent=2)
print(infos)
return infos

Expand Down
4 changes: 2 additions & 2 deletions meshtastic/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ def showInfo(self):
"""Show human readable description of our node"""
prefs = ""
if self.localConfig:
prefs = message_to_json(self.localConfig)
prefs = message_to_json(self.localConfig, multiline=True)
print(f"Preferences: {prefs}\n")
prefs = ""
if self.moduleConfig:
prefs = message_to_json(self.moduleConfig)
prefs = message_to_json(self.moduleConfig, multiline=True)
print(f"Module preferences: {prefs}\n")
self.showChannels()

Expand Down
8 changes: 5 additions & 3 deletions meshtastic/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,8 @@ def check_if_newer_version():

return pypi_version

def message_to_json(message):
"Return protobuf message as JSON. Always print all fields, even when not present in data."
return stripnl(MessageToJson(message, always_print_fields_with_no_presence=True))

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