Skip to content

Go:CLI add new response function - #16347

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
myf-bee:maoyifeng-go-cli-ky
Jun 25, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
myf-bee:maoyifeng-go-cli-ky

Conversation

@myf-bee

@myf-bee myf-bee commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

add new response function

Type of change

  • New Feature (non-breaking change which adds functionality)

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 25, 2026
@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The CLI adds ordered response wrappers for summary output, a helper to extract _columns from tabular data, and admin summary commands now unmarshal into the ordered response types.

Changes

Ordered CLI summary rendering

Layer / File(s) Summary
Table column extraction
internal/cli/table.go
ExtractColumnsAndCleanData reads _columns from the first row, strips it from each row, and returns ordered column names with cleaned data.
Ordered response printing
internal/cli/response.go
OrderedCommonResponse and OrderedCommonDataResponse add PrintOut() paths that render ordered tables when available and otherwise fall back to existing table output or field/value rows.
Admin summary command wiring
internal/cli/admin_command.go
Three admin summary commands now unmarshal JSON into the ordered response wrappers before checking response status and printing output.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • infiniflow/ragflow#16119: Adds the admin summary command handlers that this PR updates to use ordered response wrappers.
  • infiniflow/ragflow#16263: Introduces the ordered CLI response/table rendering path that this PR extends with new wrappers and column extraction.

Poem

A bunny peeks at tidy rows,
Where _columns bloom and order grows.
Hop hop—tables march in line,
With neat little fields that shine.
🐰✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The required sections are present, but the problem statement is too vague and the type-of-change selection is left unchecked. Add a brief background on the issue being solved and select the correct type-of-change checkbox, or use Other with a short explanation.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and matches the main change: adding a new CLI response function.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

❤️ Share

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

@JinHai-CN JinHai-CN added the ci Continue Integration label Jun 25, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between fb8e5ad and c5cb714.

📒 Files selected for processing (3)
  • internal/cli/admin_command.go
  • internal/cli/response.go
  • internal/cli/table.go

Comment thread internal/cli/response.go
Comment on lines +1110 to +1119
} 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 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.

Suggested change
} 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

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (c2665d4) to head (c5cb714).
⚠️ Report is 19 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit 6e7aa75 into infiniflow:main Jun 25, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants