Repository navigation
Go:cli move _order _columns sort group - #16615
Conversation
2.modify show name spaces to _ 3.remove _order _columns column sort group; 4.add dao empty enterprise file
📝 WalkthroughWalkthroughThis PR removes ordered CLI table rendering helpers, updates response printers to use raw map output, adds common byte/number/time formatting helpers, and adds three empty DAO package scaffold files. ChangesCLI Table Output Simplification
Common Formatting Helpers
Enterprise DAO Scaffold Files
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/cli/response.go (1)
1197-1232: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winSection titles no longer printed for quota summary.
The
sectionslist dropped the "title" field entirely (previouslykey/title/columns), and the loop only prints a blank-line separator between sections — no header identifying whether a table is for "storage", "apps", or "api". In table/plain format, users can no longer tell which section a given table belongs to, especially since "No data" messages are now also unlabeled.🔧 Suggested fix: restore section headers
- sections := []string{"storage", "apps", "api"} + sections := []string{"storage", "apps", "api"} + titles := map[string]string{ + "storage": "Storage", + "apps": "Apps", + "api": "API", + } for i, key := range sections { if i > 0 { fmt.Println() } + fmt.Printf("%s:\n", titles[key]) rowsRaw, ok := r.Data[key]🤖 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 1197 - 1232, The quota summary output in QuotaSummaryResponse.PrintOut no longer labels each section, so users cannot tell whether a table or “No data” message belongs to storage, apps, or api. Restore a section header per entry in the sections loop (for example by iterating over title/key metadata instead of just keys) and print it before each section’s content, including the empty-data path, while keeping the existing table rendering with PrintTableSimpleByFormat.
🧹 Nitpick comments (1)
internal/common/format.go (1)
157-162: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value
FormatTimeuses local timezone implicitly.
time.UnixMilli(*t).Format(...)renders in the server's local timezone. If callers (or display consumers) expect UTC or a consistent timezone across environments, this can produce inconsistent output depending on where the CLI runs.Consider being explicit, e.g.
time.UnixMilli(*t).UTC().Format(...)if consistency across environments is desired.🤖 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/common/format.go` around lines 157 - 162, FormatTime currently formats Unix milliseconds in the server’s local timezone, which can vary across environments. Update FormatTime to be explicit about the timezone by converting the time value in the time.UnixMilli path to UTC before formatting, so callers get consistent output regardless of where the CLI runs. Use the FormatTime function in internal/common/format.go as the place to apply this change.
🤖 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 129-138: The metric rows are built from direct map iteration in
orderedMetricTable, which makes UserIndexResponse, UserStorageResponse, and
OrderedCommonDataResponse output unstable. Update orderedMetricTable in
CommonDataResponse to collect the keys from r.Data, sort them, and then append
the "Metric"/"Value" entries in that sorted order so the output is deterministic
and the helper name remains accurate.
In `@internal/common/format.go`:
- Around line 112-123: FormatNumber currently groups the minus sign with digits
for negative values, which produces malformed output like "-,100". Update
FormatNumber to handle the sign separately from the digit grouping logic, using
the existing FormatNumber function as the target, so the loop only formats the
absolute digits and then reattaches the sign for negative inputs.
---
Outside diff comments:
In `@internal/cli/response.go`:
- Around line 1197-1232: The quota summary output in
QuotaSummaryResponse.PrintOut no longer labels each section, so users cannot
tell whether a table or “No data” message belongs to storage, apps, or api.
Restore a section header per entry in the sections loop (for example by
iterating over title/key metadata instead of just keys) and print it before each
section’s content, including the empty-data path, while keeping the existing
table rendering with PrintTableSimpleByFormat.
---
Nitpick comments:
In `@internal/common/format.go`:
- Around line 157-162: FormatTime currently formats Unix milliseconds in the
server’s local timezone, which can vary across environments. Update FormatTime
to be explicit about the timezone by converting the time value in the
time.UnixMilli path to UTC before formatting, so callers get consistent output
regardless of where the CLI runs. Use the FormatTime function in
internal/common/format.go as the place to apply this change.
🪄 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: 84078c61-d725-42a1-9851-e2cda413c108
📒 Files selected for processing (6)
internal/cli/response.gointernal/cli/table.gointernal/common/format.gointernal/dao/enterprise_data.gointernal/dao/enterprise_tasks.gointernal/dao/enterprise_user.go
💤 Files with no reviewable changes (1)
- internal/cli/table.go
| func (r *CommonDataResponse) orderedMetricTable() []map[string]interface{} { | ||
| table := make([]map[string]interface{}, 0) | ||
| if orderRaw, ok := r.Data["_order"]; ok { | ||
| if orderSlice, ok := orderRaw.([]interface{}); ok { | ||
| for _, keyRaw := range orderSlice { | ||
| key := fmt.Sprintf("%v", keyRaw) | ||
| if value, exists := r.Data[key]; exists { | ||
| table = append(table, map[string]interface{}{ | ||
| "Metric": key, | ||
| "Value": value, | ||
| }) | ||
| } | ||
| } | ||
| } | ||
| for key, value := range r.Data { | ||
| table = append(table, map[string]interface{}{ | ||
| "Metric": key, | ||
| "Value": value, | ||
| }) | ||
| } | ||
| return table | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Non-deterministic metric ordering from raw map iteration.
orderedMetricTable() now iterates r.Data (a map[string]interface{}) directly without sorting keys. Go's for range over a map has randomized iteration order, so the "Metric"/"Value" rows built here — and consumed by UserIndexResponse (Line 1010), UserStorageResponse (Line 1069), and OrderedCommonDataResponse (Line 1171) — will print in a different order on every invocation, including in JSON output. This also makes the function name misleading, since it no longer orders anything.
🔧 Suggested fix: sort keys for stable output
+import "sort"
+
func (r *CommonDataResponse) orderedMetricTable() []map[string]interface{} {
table := make([]map[string]interface{}, 0)
- for key, value := range r.Data {
- table = append(table, map[string]interface{}{
- "Metric": key,
- "Value": value,
- })
- }
+ keys := make([]string, 0, len(r.Data))
+ for key := range r.Data {
+ keys = append(keys, key)
+ }
+ sort.Strings(keys)
+ for _, key := range keys {
+ table = append(table, map[string]interface{}{
+ "Metric": key,
+ "Value": r.Data[key],
+ })
+ }
return table
}Also applies to: 1010-1010, 1069-1069, 1171-1171
🤖 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 129 - 138, The metric rows are built
from direct map iteration in orderedMetricTable, which makes UserIndexResponse,
UserStorageResponse, and OrderedCommonDataResponse output unstable. Update
orderedMetricTable in CommonDataResponse to collect the keys from r.Data, sort
them, and then append the "Metric"/"Value" entries in that sorted order so the
output is deterministic and the helper name remains accurate.
| func FormatNumber(n int64) string { | ||
| s := fmt.Sprintf("%d", n) | ||
| parts := []string{} | ||
| for i := len(s); i > 0; i -= 3 { | ||
| start := i - 3 | ||
| if start < 0 { | ||
| start = 0 | ||
| } | ||
| parts = append([]string{s[start:i]}, parts...) | ||
| } | ||
| return strings.Join(parts, ",") | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
FormatNumber mis-groups the sign for negative numbers.
The digit-grouping loop treats the leading - sign as part of a 3-character group, producing incorrect output whenever the digit count isn't a multiple of 3. E.g. FormatNumber(-100) returns "-,100" instead of "-100".
🐛 Proposed fix to handle the sign separately
func FormatNumber(n int64) string {
- s := fmt.Sprintf("%d", n)
+ sign := ""
+ if n < 0 {
+ sign = "-"
+ n = -n
+ }
+ s := fmt.Sprintf("%d", n)
parts := []string{}
for i := len(s); i > 0; i -= 3 {
start := i - 3
if start < 0 {
start = 0
}
parts = append([]string{s[start:i]}, parts...)
}
- return strings.Join(parts, ",")
+ return sign + strings.Join(parts, ",")
}🤖 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/common/format.go` around lines 112 - 123, FormatNumber currently
groups the minus sign with digits for negative values, which produces malformed
output like "-,100". Update FormatNumber to handle the sign separately from the
digit grouping logic, using the existing FormatNumber function as the target, so
the loop only formats the absolute digits and then reattaches the sign for
negative inputs.
### Summary 1. Move common functions to format.go 2. modify show name spaces to _ 3. move _order _columns column sort group; 4. add dao empty enterprise file
### Summary 1. Move common functions to format.go 2. modify show name spaces to _ 3. move _order _columns column sort group; 4. add dao empty enterprise file
Summary