Skip to content

Commit 1abb9fb

Browse files
committed
refactor getPref to use uniform printing logic
We add a local helper function to print a single setting. This is a preparation to correctly print non-trivial types. The existing code in getPref is ported over to use that function. By that, the output of "wholeField" is changed slightly to always print the full path for each setting (e.g. "security.serialEnabled" instead of "security:\nserialEnabled"). This improves support for grepping on the output.
1 parent 7fcbbe9 commit 1abb9fb

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

meshtastic/__main__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ def checkChannel(interface: MeshInterface, channelIndex: int) -> bool:
8787

8888
def getPref(node, comp_name):
8989
"""Get a channel or preferences value"""
90+
def _printSetting(config_type, uni_name, pref_value):
91+
"""Pretty print the setting"""
92+
print(f"{str(config_type.name)}.{uni_name}: {str(pref_value)}")
93+
logging.debug(f"{str(config_type.name)}.{uni_name}: {str(pref_value)}")
9094

9195
name = splitCompoundName(comp_name)
9296
wholeField = name[0] == name[1] # We want the whole field
@@ -114,7 +118,7 @@ def getPref(node, comp_name):
114118

115119
if not found:
116120
print(
117-
f"{localConfig.__class__.__name__} and {moduleConfig.__class__.__name__} do not have an attribute {uni_name}."
121+
f"{localConfig.__class__.__name__} and {moduleConfig.__class__.__name__} do not have attribute {uni_name}."
118122
)
119123
print("Choices are...")
120124
printConfig(localConfig)
@@ -127,11 +131,10 @@ def getPref(node, comp_name):
127131
config_values = getattr(config, config_type.name)
128132
if not wholeField:
129133
pref_value = getattr(config_values, pref.name)
130-
print(f"{str(config_type.name)}.{uni_name}: {str(pref_value)}")
131-
logging.debug(f"{str(config_type.name)}.{uni_name}: {str(pref_value)}")
134+
_printSetting(config_type, uni_name, pref_value)
132135
else:
133-
print(f"{str(config_type.name)}:\n{str(config_values)}")
134-
logging.debug(f"{str(config_type.name)}: {str(config_values)}")
136+
for field in config_values.ListFields():
137+
_printSetting(config_type, field[0].name, field[1])
135138
else:
136139
# Always show whole field for remote node
137140
node.requestConfig(config_type)

0 commit comments

Comments
 (0)