Skip to content

Refactor printConfig to display aligned types and enum options#945

Open
Samith-NM wants to merge 1 commit into
meshtastic:masterfrom
Samith-NM:improve-config-choices-formatting
Open

Refactor printConfig to display aligned types and enum options#945
Samith-NM wants to merge 1 commit into
meshtastic:masterfrom
Samith-NM:improve-config-choices-formatting

Conversation

@Samith-NM

@Samith-NM Samith-NM commented Jul 2, 2026

Copy link
Copy Markdown

modified the printConfig function to make more user friendly interaction in CLI as per the issue #393

Summary by CodeRabbit

  • New Features
    • Expanded configuration output to show more helpful field details, including field type information, option hints, and available enum values.
    • Improved field labeling for clearer, more readable config listings, with smarter formatting for supported display styles.

@CLAassistant

CLAassistant commented Jul 2, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The printConfig function in meshtastic/main.py was modified to enrich per-field output with derived metadata including protobuf type labels, human-readable descriptions, boolean/options hints, and enum value listings, replacing the prior simple field-name listing with sorted, enriched output lines.

Changes

printConfig Output Enrichment

Layer / File(s) Summary
Enrich and sort printed config field lines
meshtastic/__main__.py
Adds type_map and descriptions dictionaries, computes a lookup_name per field with optional camelCase conversion based on mt_config.camel_case, appends derived type/boolean/enum metadata to each field line, then collects, sorts, and prints the enriched lines instead of plain field names.

Estimated code review effort: 2 (Simple) | ~10 minutes

Related PRs: None identified.

Suggested labels: enhancement

Suggested reviewers: None identified.

🐰 A rabbit taps keys with delicate care,
Sorting config lines out in the air,
Types now labeled, enums in tow,
A tidier printout begins to show.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: refactoring printConfig to show types and enum options in the CLI.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
meshtastic/__main__.py (2)

1222-1222: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Inconsistent capitalization: "options" vs "Options".

Boolean fields print options: True/False (lowercase) while enum fields print Options: ... (uppercase), creating an inconsistent CLI output style.

✏️ Suggested fix
-                opts = "  ||  options: True/False" if f_type == "bool" else ""
+                opts = "  ||  Options: True/False" if f_type == "bool" else ""

Also applies to: 1224-1224

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@meshtastic/__main__.py` at line 1222, The CLI help text formatting is
inconsistent between boolean and enum fields because the boolean branch in the
field-description logic uses lowercase “options” while the enum branch uses
uppercase “Options”. Update the string built in the relevant help/output path in
meshtastic.__main__ so both branches use the same capitalization, and make sure
the formatting stays consistent wherever these field types are rendered.

1211-1211: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid reassigning the config parameter.

config (the function parameter holding the outer message) is overwritten each iteration with a field descriptor from fields_by_name. It still works here since objDesc was already captured before the loop, but shadowing a parameter with an unrelated type is confusing and risks bugs if the function is extended later to reference the original config after this point.

♻️ Suggested rename
     for config_section in objDesc.fields:
         if config_section.name != "version":
-            config = objDesc.fields_by_name.get(config_section.name)
+            field_desc = objDesc.fields_by_name.get(config_section.name)
             print(f"{config_section.name}:")
             names = []
-            for field in config.message_type.fields:
+            for field in field_desc.message_type.fields:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@meshtastic/__main__.py` at line 1211, The `config` parameter in the function
containing `objDesc.fields_by_name.get(config_section.name)` is being reassigned
to a field descriptor, which shadows the original outer message object and is
confusing. Rename the local variable to something like `field` or `config_field`
and update the subsequent references in that loop so the original `config` value
remains intact for future use.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@meshtastic/__main__.py`:
- Line 1204: The printConfig type labeling is incomplete because type_map in
printConfig does not cover protobuf float fields, leaving config entries like
frequency_offset as unknown. Update the type resolution in printConfig by adding
the float cpp_type to type_map or deriving the label from field.cpp_type so all
supported config field types are printed consistently. Keep the change localized
to the type_map/field type handling logic in printConfig.

---

Nitpick comments:
In `@meshtastic/__main__.py`:
- Line 1222: The CLI help text formatting is inconsistent between boolean and
enum fields because the boolean branch in the field-description logic uses
lowercase “options” while the enum branch uses uppercase “Options”. Update the
string built in the relevant help/output path in meshtastic.__main__ so both
branches use the same capitalization, and make sure the formatting stays
consistent wherever these field types are rendered.
- Line 1211: The `config` parameter in the function containing
`objDesc.fields_by_name.get(config_section.name)` is being reassigned to a field
descriptor, which shadows the original outer message object and is confusing.
Rename the local variable to something like `field` or `config_field` and update
the subsequent references in that loop so the original `config` value remains
intact for future use.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 60b4dc3e-2aa1-4e67-996a-9cffe80ac93b

📥 Commits

Reviewing files that changed from the base of the PR and between 7a7353c and 6bb0920.

📒 Files selected for processing (1)
  • meshtastic/__main__.py

Comment thread meshtastic/__main__.py
def printConfig(config) -> None:
"""print configuration"""
objDesc = config.DESCRIPTOR
type_map = {5: "int", 8: "bool", 9: "str", 13: "int", 14: "enum"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Does the Meshtastic protobuf config (meshtastic/config.proto) use float or double fields?

💡 Result:

The Meshtastic protobuf configuration file (meshtastic/config.proto) uses float fields for certain parameters, such as frequency_offset [1][2]. It does not typically use double fields for configuration values [1][2]. The protobuf definitions rely on standard scalar types provided by Protocol Buffers, and the official source code confirms the use of float where floating-point precision is required for configuration settings [1][2].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the type_map and nearby logic.
sed -n '1188,1235p' meshtastic/__main__.py | cat -n

# Find protobuf config definitions in the repo and inspect scalar field types.
fd -a 'config.proto' .
fd -a '*.proto' meshtastic 2>/dev/null || true

# Search for floating-point and other scalar types in protobufs.
rg -n '\b(float|double|fixed32|fixed64|sfixed32|sfixed64|sint32|sint64|bytes)\b' meshtastic protobufs . -g '*.proto' -g '!**/.git/**' || true

# If config.proto exists in-repo, show relevant excerpts with line numbers.
if [ -f meshtastic/config.proto ]; then
  rg -n '^\s*(float|double|fixed32|fixed64|sfixed32|sfixed64|sint32|sint64|bytes|int32|uint32|bool|string|enum)\b' meshtastic/config.proto
fi

Repository: meshtastic/python

Length of output: 2399


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate the protobuf config file(s) and inspect scalar field declarations.
fd -a 'config.proto' .
if [ -f meshtastic/config.proto ]; then
  echo '--- meshtastic/config.proto scalar declarations ---'
  rg -n '^\s*(optional|required|repeated)?\s*(float|double|fixed32|fixed64|sfixed32|sfixed64|sint32|sint64|bytes|int32|uint32|bool|string|enum)\b' meshtastic/config.proto || true
fi

# Show every place in __main__.py where field.type is mapped or rendered.
echo '--- __main__.py field.type references ---'
rg -n 'field\.type|cpp_type|type_map|unknown' meshtastic/__main__.py

# Show a little more context around the relevant function, including the second line mentioned in the review.
sed -n '1200,1225p' meshtastic/__main__.py | cat -n

Repository: meshtastic/python

Length of output: 1747


Handle protobuf float fields in printConfig type_map currently leaves Meshtastic config float fields as "unknown" (for example, frequency_offset), so the type labels are still incomplete. Expanding the mapping or deriving the label from field.cpp_type would make the output consistently user-friendly.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@meshtastic/__main__.py` at line 1204, The printConfig type labeling is
incomplete because type_map in printConfig does not cover protobuf float fields,
leaving config entries like frequency_offset as unknown. Update the type
resolution in printConfig by adding the float cpp_type to type_map or deriving
the label from field.cpp_type so all supported config field types are printed
consistently. Keep the change localized to the type_map/field type handling
logic in printConfig.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants