Repository navigation
Go: refactor CLI - #15898
Go: refactor CLI#15898
Conversation
Signed-off-by: Jin Hai <[email protected]>
📝 WalkthroughWalkthroughThis PR consolidates the CLI structure by eliminating the ChangesCLI Structure and Auth Refactoring
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
🚥 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
internal/cli/cli.go (1)
589-611:⚠️ Potential issue | 🟠 Major | ⚡ Quick win
ReadPassworderror silently dropped in both API and admin password prompts.Both password prompting loops (API mode at lines 589-611 and admin mode at lines 616-648) capture
errfromReadPassword()but only checkpassword == "". IfReadPasswordreturns an I/O error, that error is silently overwritten whenVerifyAuthis called. The fix is the same for both: checkerr != nilimmediately after theReadPassword()call.🤖 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/cli.go` around lines 589 - 611, ReadPassword's returned error is ignored; after calling ReadPassword() in both password prompts check err != nil immediately and handle/return it instead of letting it be overwritten by later logic. Specifically, in the API prompt block that sets apiConfig.UserPassword and calls c.VerifyAuth(*apiConfig.UserName, *apiConfig.UserPassword), and in the admin prompt block that mirrors this flow, add an immediate error check for the local err from ReadPassword() and return or surface that error before inspecting password == "" or calling VerifyAuth(), so I/O errors aren't silently dropped.cmd/ragflow_cli.go (1)
31-34:⚠️ Potential issue | 🟡 MinorInconsistent CLI error handling for
ParseArgsfailuresWhen
cli.ParseArgsreturns an error,main()justreturns (no message, implicit exit code 0), unlike other error paths in this file that print the error and callos.Exit(1).🐛 Suggested fix
parseArgs, err := cli.ParseArgs(os.Args[1:]) if err != nil { + fmt.Printf("Argument parsing failed: %v\n", err) + os.Exit(1) return }🤖 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 `@cmd/ragflow_cli.go` around lines 31 - 34, The ParseArgs error path in main silently returns; change it to mirror other error handling by printing the error and exiting with non-zero status: capture the error returned from cli.ParseArgs(os.Args[1:]), log or fmt.Fprintln(os.Stderr, err) (or use the existing logger), and call os.Exit(1) instead of returning so failures in ParseArgs result in an error message and exit code 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.
Outside diff comments:
In `@cmd/ragflow_cli.go`:
- Around line 31-34: The ParseArgs error path in main silently returns; change
it to mirror other error handling by printing the error and exiting with
non-zero status: capture the error returned from cli.ParseArgs(os.Args[1:]), log
or fmt.Fprintln(os.Stderr, err) (or use the existing logger), and call
os.Exit(1) instead of returning so failures in ParseArgs result in an error
message and exit code 1.
In `@internal/cli/cli.go`:
- Around line 589-611: ReadPassword's returned error is ignored; after calling
ReadPassword() in both password prompts check err != nil immediately and
handle/return it instead of letting it be overwritten by later logic.
Specifically, in the API prompt block that sets apiConfig.UserPassword and calls
c.VerifyAuth(*apiConfig.UserName, *apiConfig.UserPassword), and in the admin
prompt block that mirrors this flow, add an immediate error check for the local
err from ReadPassword() and return or surface that error before inspecting
password == "" or calling VerifyAuth(), so I/O errors aren't silently dropped.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 37f2a973-722b-4b9d-84d5-33e1d1f8a81d
📒 Files selected for processing (5)
cmd/ragflow_cli.gointernal/cli/cli.gointernal/cli/client.gointernal/cli/common_command.gointernal/cli/http_client.go
💤 Files with no reviewable changes (1)
- internal/cli/client.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15898 +/- ##
=======================================
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?
Type of change