Skip to content

Add consistent --format json support to CLI commands (MIR-662)#687

Merged
evanphx merged 3 commits intomainfrom
mir-662-audit-cli-commands-for-consistent-json-output-supp
Mar 23, 2026
Merged

Add consistent --format json support to CLI commands (MIR-662)#687
evanphx merged 3 commits intomainfrom
mir-662-audit-cli-commands-for-consistent-json-output-supp

Conversation

@evanphx
Copy link
Copy Markdown
Contributor

@evanphx evanphx commented Mar 18, 2026

Summary

  • Add --format json support to debug netdb list, debug netdb status, and doctor config commands using the established FormatOptions pattern
  • Change FormatOptions default from "table" to "text" since not all commands using it render tables
  • Add --json as a shorthand for --format json on all commands that embed FormatOptions
  • Migrate whoami from its own --json flag to use FormatOptions for consistency
  • Document the FormatOptions pattern in CLAUDE.md for future CLI commands

Test plan

  • go vet ./cli/commands/ passes
  • make lint passes with 0 issues
  • Manual: m debug netdb list --format json / m debug netdb list --json
  • Manual: m debug netdb status --json
  • Manual: m doctor config --json
  • Manual: m whoami --json (still works after migration)

evanphx added 3 commits March 18, 2026 13:54
…IR-662)

Add FormatOptions to DebugNetDBList, DebugNetDBStatus, and DoctorConfig
so they support --format json for machine-readable output. Also document
the FormatOptions pattern in CLAUDE.md for future CLI commands.
Some commands using FormatOptions don't render tables, so "text" is a
more accurate default name. No behavior change since all consumers only
check IsJSON().
…IR-662)

Add a --json bool flag to FormatOptions as a shorthand for --format json.
Migrate whoami from its own --json flag to FormatOptions, using PrintJSON
for consistent output. Admin's --json is intentionally left as-is since it
controls TTY-aware JSON highlighting, not the text/json format switch.
@evanphx evanphx requested a review from a team as a code owner March 18, 2026 21:02
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 18, 2026

📝 Walkthrough

Walkthrough

This pull request introduces standardized JSON output support across CLI commands through a FormatOptions pattern. Changes include: updating CLAUDE.md documentation to describe the JSON formatting approach; adding FormatOptions with a JSON boolean flag to format.go; refactoring whoami.go to embed FormatOptions instead of using a direct JSON flag; adding JSON output paths to debug_netdb.go commands (DebugNetDBList and DebugNetDBStatus) with custom JSON struct types; and adding JSON export functionality to DoctorConfig in doctor_config.go. Commands now use an IsJSON() check to determine whether to output JSON via PrintJSON or return human-readable table output.

📝 Coding Plan
  • Generate coding plan for human review comments

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

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
cli/commands/debug_netdb.go (1)

136-162: LGTM! JSON output follows the documented pattern.

Using float64 for usage_percent (rather than a formatted string like "85.0%") aligns well with the CLAUDE.md guidance to use raw/machine-readable values in JSON.

💡 Optional: Extract usage calculation to avoid duplication

The usage percentage calculation appears in both the JSON path (lines 149-152) and table path (lines 171-173). If you'd like to DRY this up:

+func usagePercent(reserved, capacity int32) float64 {
+	if capacity > 0 {
+		return float64(reserved) / float64(capacity) * 100
+	}
+	return 0
+}

Then use usagePercent(reserved, capacity) in both places. This is minor and optional.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cli/commands/debug_netdb.go` around lines 136 - 162, The JSON branch
duplicates the usage-percentage math (currently computed inline when building
SubnetJSON before calling PrintJSON(items)); extract that logic into a small
helper function usagePercent(reserved int32, capacity int32) float64 and replace
the inline calculation in the JSON path (where SubnetJSON is constructed using
subnet.Capacity(), subnet.Reserved(), subnet.Released()) with a call to
usagePercent, then update the other location that computes the same value in the
table path to call usagePercent as well so both paths share the same
implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cli/commands/debug_netdb.go`:
- Around line 136-162: The JSON branch duplicates the usage-percentage math
(currently computed inline when building SubnetJSON before calling
PrintJSON(items)); extract that logic into a small helper function
usagePercent(reserved int32, capacity int32) float64 and replace the inline
calculation in the JSON path (where SubnetJSON is constructed using
subnet.Capacity(), subnet.Reserved(), subnet.Released()) with a call to
usagePercent, then update the other location that computes the same value in the
table path to call usagePercent as well so both paths share the same
implementation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 00326450-2758-4c7c-a179-cbe94ba42467

📥 Commits

Reviewing files that changed from the base of the PR and between 38cfa08 and 9f2bc34.

📒 Files selected for processing (5)
  • CLAUDE.md
  • cli/commands/debug_netdb.go
  • cli/commands/doctor_config.go
  • cli/commands/format.go
  • cli/commands/whoami.go

@evanphx evanphx merged commit 316ceaf into main Mar 23, 2026
13 checks passed
@evanphx evanphx deleted the mir-662-audit-cli-commands-for-consistent-json-output-supp branch March 23, 2026 20:29
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