Repository navigation
Go:CLI add new response function - #16347
Conversation
📝 WalkthroughWalkthroughThe CLI adds ordered response wrappers for summary output, a helper to extract ChangesOrdered CLI summary rendering
Sequence Diagram(s)sequenceDiagram
participant OrderedCommonResponse
participant ExtractColumnsAndCleanData
participant PrintTableSimpleByFormatWithOrder
participant PrintTableSimpleByFormat
OrderedCommonResponse->>ExtractColumnsAndCleanData: ExtractColumnsAndCleanData(r.Data)
alt columns extracted
ExtractColumnsAndCleanData-->>OrderedCommonResponse: colNames, cleanData, true
OrderedCommonResponse->>PrintTableSimpleByFormatWithOrder: print ordered columns and cleaned rows
else no ordered columns
ExtractColumnsAndCleanData-->>OrderedCommonResponse: false
OrderedCommonResponse->>PrintTableSimpleByFormat: print r.Data
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@internal/cli/response.go`:
- Around line 1110-1119: The fallback in response formatting is iterating over
r.Data as a map, so the {field, value} rows printed by PrintTableSimpleByFormat
can appear in random order. Update the fallback block in response.go to collect
the keys from r.Data, sort them before building the table, and then append rows
in that sorted order so the output is stable; make sure the sort package is
imported.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7116dc12-850f-4b02-b1d0-c723fb68e87d
📒 Files selected for processing (3)
internal/cli/admin_command.gointernal/cli/response.gointernal/cli/table.go
| } else { | ||
| table := make([]map[string]interface{}, 0) | ||
| for key, value := range r.Data { | ||
| elem := map[string]interface{}{ | ||
| "field": key, | ||
| "value": value, | ||
| } | ||
| table = append(table, elem) | ||
| } | ||
| PrintTableSimpleByFormat(table, r.OutputFormat) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Fallback row order is non-deterministic.
The fallback builds {field, value} rows by ranging over r.Data, a map. Go randomizes map iteration order, so the printed rows shuffle across runs — undermining the "Ordered" intent of this wrapper. Sort by key to get stable output.
♻️ Stabilize fallback ordering
} else {
table := make([]map[string]interface{}, 0)
- for key, value := range r.Data {
+ keys := make([]string, 0, len(r.Data))
+ for key := range r.Data {
+ keys = append(keys, key)
+ }
+ sort.Strings(keys)
+ for _, key := range keys {
elem := map[string]interface{}{
"field": key,
- "value": value,
+ "value": r.Data[key],
}
table = append(table, elem)
}
PrintTableSimpleByFormat(table, r.OutputFormat)
}Ensure sort is imported.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| } else { | |
| table := make([]map[string]interface{}, 0) | |
| for key, value := range r.Data { | |
| elem := map[string]interface{}{ | |
| "field": key, | |
| "value": value, | |
| } | |
| table = append(table, elem) | |
| } | |
| PrintTableSimpleByFormat(table, r.OutputFormat) | |
| } else { | |
| table := make([]map[string]interface{}, 0) | |
| keys := make([]string, 0, len(r.Data)) | |
| for key := range r.Data { | |
| keys = append(keys, key) | |
| } | |
| sort.Strings(keys) | |
| for _, key := range keys { | |
| elem := map[string]interface{}{ | |
| "field": key, | |
| "value": r.Data[key], | |
| } | |
| table = append(table, elem) | |
| } | |
| PrintTableSimpleByFormat(table, r.OutputFormat) |
🤖 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 `@internal/cli/response.go` around lines 1110 - 1119, The fallback in response
formatting is iterating over r.Data as a map, so the {field, value} rows printed
by PrintTableSimpleByFormat can appear in random order. Update the fallback
block in response.go to collect the keys from r.Data, sort them before building
the table, and then append rows in that sorted order so the output is stable;
make sure the sort package is imported.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16347 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What problem does this PR solve?
add new response function
Type of change