Skip to content

Refactor printConfig to display aligned types and enum options#945

Open
Samith-NM wants to merge 2 commits 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 2 commits 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
    • Enhanced configuration output with richer per-field details, including protobuf-derived type information, option hints, and human-readable descriptions.
    • When enum metadata is available, enum value options are now displayed alongside their corresponding fields.
    • Improved readability through smarter field-name formatting (including optional camelCase) and consistently sorted field listings.

@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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 8b4d666a-b51e-42d8-a644-384f9a329e58

📥 Commits

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

📒 Files selected for processing (1)
  • meshtastic/__main__.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • meshtastic/main.py

📝 Walkthrough

Walkthrough

printConfig in meshtastic/__main__.py now formats each config field with derived type, description, boolean option, and enum metadata, then sorts and prints the enriched lines instead of only field names.

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

🚥 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.
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 Outdated
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