Conversation
…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.
📝 WalkthroughWalkthroughThis 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
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cli/commands/debug_netdb.go (1)
136-162: LGTM! JSON output follows the documented pattern.Using
float64forusage_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
📒 Files selected for processing (5)
CLAUDE.mdcli/commands/debug_netdb.gocli/commands/doctor_config.gocli/commands/format.gocli/commands/whoami.go
Summary
--format jsonsupport todebug netdb list,debug netdb status, anddoctor configcommands using the establishedFormatOptionspatternFormatOptionsdefault from"table"to"text"since not all commands using it render tables--jsonas a shorthand for--format jsonon all commands that embedFormatOptionswhoamifrom its own--jsonflag to useFormatOptionsfor consistencyFormatOptionspattern in CLAUDE.md for future CLI commandsTest plan
go vet ./cli/commands/passesmake lintpasses with 0 issuesm debug netdb list --format json/m debug netdb list --jsonm debug netdb status --jsonm doctor config --jsonm whoami --json(still works after migration)