Repository navigation
Go CLI: add response output - #16263
Conversation
📝 WalkthroughWalkthroughThe PR adds three new CLI response types ( ChangesAdmin User Stats Response Types and Table Rendering
Sequence Diagram(s)sequenceDiagram
participant CLI as AdminShow* Command
participant API as RAGFlow API
participant ResponseType as UserStorage/Quota/IndexResponse
participant Table as PrintTableSimpleByFormatWithOrder
CLI->>API: GET /admin/users/{user}/storage|quota|index
API-->>CLI: JSON response body
CLI->>ResponseType: json.Unmarshal(body)
ResponseType->>ResponseType: PrintOut()
alt Code != 0
ResponseType-->>CLI: print error, return
end
alt OutputFormatJSON
ResponseType-->>CLI: print raw JSON
else formatted
ResponseType->>ResponseType: orderedMetricTable()
ResponseType->>Table: PrintTableSimpleByFormatWithOrder(summary rows, columns, format)
Table-->>CLI: render summary table
ResponseType->>Table: PrintTableSimpleByFormatWithOrder(data rows, columns, format)
Table-->>CLI: render data table (files/indices/rows)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✅ Passed checks (2 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: 2
🤖 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/admin_command.go`:
- Around line 2082-2084: The error messages in the quota and index handler
functions contain generic "user storage" context strings that don't accurately
reflect the specific operation being performed. Update all error messages at
lines 2075, 2079, 2111, 2115, and 2118-2120 to use operation-specific context
instead of the copied generic text. For quota-related operations, use "get user
quota failed" as the error prefix (matching the pattern shown in the JSON
unmarshal error at line 2083), and for index-related operations, use appropriate
index-specific error context. This ensures error messages clearly indicate which
operation failed during troubleshooting.
In `@internal/cli/response.go`:
- Around line 972-974: The conditional check `if len(summaryTable) > 0`
suppresses the output of PrintTableSimpleByFormatWithOrder when the summaryTable
is empty, causing inconsistent CLI output contracts (particularly breaking JSON
format output on empty results). Remove the if condition and call
PrintTableSimpleByFormatWithOrder unconditionally with the summaryTable, the
column order array with "Metric", "Used", and "Limit", and r.OutputFormat, so
that output is always emitted regardless of whether summaryTable has rows or
not.
🪄 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: 3464228a-5bb1-4c9e-8f5f-a8bd9a775c87
📒 Files selected for processing (4)
internal/cli/admin_command.gointernal/cli/response.gointernal/cli/table.gointernal/engine/elasticsearch/client.go
| var result UserQuotaResponse | ||
| if err = json.Unmarshal(resp.Body, &result); err != nil { | ||
| return nil, fmt.Errorf("get user storage failed: invalid JSON (%w)", err) | ||
| return nil, fmt.Errorf("get user quota failed: invalid JSON (%w)", err) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Fix copied error context in quota/index handlers.
After these type-specific updates, request/status failures in the same handlers still report "user storage" (Line 2075, Line 2079, Line 2111, Line 2115), which is misleading during troubleshooting.
Proposed fix
func (c *CLI) AdminShowUserQuotaCommand(cmd *Command) (ResponseIf, error) {
@@
- if err != nil {
- return nil, fmt.Errorf("failed to get user storage: %w", err)
- }
+ if err != nil {
+ return nil, fmt.Errorf("failed to get user quota: %w", err)
+ }
@@
- if resp.StatusCode != 200 {
- return nil, fmt.Errorf("failed to get user storage: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
- }
+ if resp.StatusCode != 200 {
+ return nil, fmt.Errorf("failed to get user quota: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
+ }
@@
func (c *CLI) AdminShowUserIndexCommand(cmd *Command) (ResponseIf, error) {
@@
- if err != nil {
- return nil, fmt.Errorf("failed to get user storage: %w", err)
- }
+ if err != nil {
+ return nil, fmt.Errorf("failed to get user index: %w", err)
+ }
@@
- if resp.StatusCode != 200 {
- return nil, fmt.Errorf("failed to get user storage: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
- }
+ if resp.StatusCode != 200 {
+ return nil, fmt.Errorf("failed to get user index: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
+ }Also applies to: 2118-2120
🤖 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/admin_command.go` around lines 2082 - 2084, The error messages
in the quota and index handler functions contain generic "user storage" context
strings that don't accurately reflect the specific operation being performed.
Update all error messages at lines 2075, 2079, 2111, 2115, and 2118-2120 to use
operation-specific context instead of the copied generic text. For quota-related
operations, use "get user quota failed" as the error prefix (matching the
pattern shown in the JSON unmarshal error at line 2083), and for index-related
operations, use appropriate index-specific error context. This ensures error
messages clearly indicate which operation failed during troubleshooting.
| if len(summaryTable) > 0 { | ||
| PrintTableSimpleByFormatWithOrder(summaryTable, []string{"Metric", "Used", "Limit"}, r.OutputFormat) | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Always emit quota output, even when rows are empty.
Line 972 suppresses output entirely for empty rows, so OutputFormatJSON returns no JSON at all on a successful empty result. Prefer printing via the table helper unconditionally to preserve consistent CLI output contracts.
Proposed fix
- if len(summaryTable) > 0 {
- PrintTableSimpleByFormatWithOrder(summaryTable, []string{"Metric", "Used", "Limit"}, r.OutputFormat)
- }
+ PrintTableSimpleByFormatWithOrder(summaryTable, []string{"Metric", "Used", "Limit"}, r.OutputFormat)📝 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.
| if len(summaryTable) > 0 { | |
| PrintTableSimpleByFormatWithOrder(summaryTable, []string{"Metric", "Used", "Limit"}, r.OutputFormat) | |
| } | |
| PrintTableSimpleByFormatWithOrder(summaryTable, []string{"Metric", "Used", "Limit"}, 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 972 - 974, The conditional check `if
len(summaryTable) > 0` suppresses the output of
PrintTableSimpleByFormatWithOrder when the summaryTable is empty, causing
inconsistent CLI output contracts (particularly breaking JSON format output on
empty results). Remove the if condition and call
PrintTableSimpleByFormatWithOrder unconditionally with the summaryTable, the
column order array with "Metric", "Used", and "Limit", and r.OutputFormat, so
that output is always emitted regardless of whether summaryTable has rows or
not.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16263 +/- ##
=======================================
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?
Go CLI: add response output
Type of change