[Bug]: Go CLI single-command mode panics without a command, appends the connection flags to the command, and cannot dispatch `ws`/`ws delete` · Issue #22651 · infiniflow/ragflow · GitHub
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on anoth
8000
er tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Go CLI single-command mode panics without a command, appends the connection flags to the command, and cannot dispatch ws/ws delete #22651
RAGFlow main at d6fd68a88 (the refactor cli: single command change #22633), macOS arm64, CGO_ENABLED=0 go build -o ragflow-cli cmd/ragflow-cli.go.
What happens
CommandMode became the default mode in #22633 and the single-command wiring does not survive its own documented usage.
1. A bare ragflow-cli panics instead of opening the REPL.PrintUsage says "If no command is provided, CLI runs in interactive mode", and ParseArgs leaves Command nil in that case, but main dispatches on CLIMode == CommandMode:
Flag-only invocations panic the same way (ragflow-cli -v, ragflow-cli -o json). Even with the dispatch guarded, Run() has no CommandMode branch and replies unexpected CLI mode: command.
2. The connection flags are glued onto the command text.ParseArgs copies every argv entry into commandArgs for CommandMode, and unlike APIMode it never parses -h/-t/-u/-p/-f/-k, so the documented ragflow-cli -f rf.yml ls datasets form fails:
3. ws and ws delete <name> cannot be dispatched.ExecuteSingleCommand switches on "single_show_workspace" while the parser emits "single_show_current_workspace", and it has no case for "single_delete_workspace" at all, although SingleDeleteWorkspaceCommand exists:
The other commands (ws ls, ws cat, ws search, ws find, ws use, ws new, ws save) reach their handlers.
Expected
No command → interactive REPL, as documented.
Connection flags configure the API client and never appear in the command text.
Every command type the single-mode parser emits has a handler.
Fix
All three are small wiring mistakes; a fix PR is linked below and covers them with tests (go test ./internal/cli/), including a red run against d6fd68a88.
@JinHai-CN Understood on the design: single-command mode reads the default rf.yml, and argv is the command itself.
Current PR #22650 goes the other way in two places, and I will drop both: it parses -h/-t/-u/-p/-f/-k (letting -f point at another config file and logging in interactively when -u/-p are given); upstream main instead reads the fixed rf.yml and copies every argv entry into the command text.
What I would keep from #22650, since it does not change where config comes from:
no command → interactive REPL instead of the RunSingleCommand nil dereference;
every command type the single-mode parser emits reaches its handler (ws, ws delete currently fail with single command mode: …);
reserved words (find, ws, new, …) still parse where a free-form word is expected.
One point needs your call: should single-command mode accept the output switches (-o, --verbose) at all? Today ParseArgs parses them but leaves them in the command text, so ragflow-cli -o json ws ls fails with expected command, got -.
Reject every leading switch with a clear message ("single-command mode reads rf.yml; pass only the command"), including -h/-t/-u/-p/-f/-k.
Keep -o/--verbose as the only global switches and strip them from the command text, so an agent can ask for JSON.
I will align #22650 with whichever you prefer; if it is (1) I will also make the connection flags fail with that message instead of being parsed.
Implemented in #22650 at 7194b50be, following your direction:
Single-command mode reads its settings from the default rf.yml only. -h/-t/-u/-p/-f/-k are rejected with single-command mode reads its settings from rf.yml; <flag> is not accepted, so -f can no longer point at another file and -u/-p no longer trigger an interactive login.
The command text is the argv words only. -o/--output, -v/--verbose, --help and --version remain global switches and are stripped, since your example shows ragflow-cli -o json ws ls as the agent-facing form; say the word if you would rather reject those too and I will drop them.
A rejected parse now prints the error instead of exiting silently, so the message is actually visible.
The rest of the PR is unchanged: no-command opens the REPL, ws / ws delete reach their handlers, and reserved words parse as names and one-word questions.
Verification (local, CGO_ENABLED=0): go test -count=1 ./internal/cli/ → ok; go vet ./internal/cli/ → clean. Binary checks: ragflow-cli -f rf.yml ls datasets → the rf.yml rejection, exit 1; ragflow-cli -o json ws ls → command runs; bare ragflow-cli → RAGFlow(user)> REPL.
The help text and PR description now document the single-command rule instead of the old -f rf.yml ... examples.
Activity
JinHai-CN commentedon Nov 23, 2026
SingleCommand mode is intended to prepare ragflow-cli for agent use, and the implementation in this PR does not align with that goal.
In SingleCommand mode, the server configuration is read from the default YAML file. The command-line argument is only the command itself.
ccclucky commentedon Nov 23, 2026
@JinHai-CN Understood on the design: single-command mode reads the default
rf.yml, and argv is the command itself.Current PR #22650 goes the other way in two places, and I will drop both: it parses
-h/-t/-u/-p/-f/-k(letting-fpoint at another config file and logging in interactively when-u/-pare given); upstreammaininstead reads the fixedrf.ymland copies every argv entry into the command text.What I would keep from #22650, since it does not change where config comes from:
RunSingleCommandnil dereference;ws,ws deletecurrently fail withsingle command mode: …);find,ws,new, …) still parse where a free-form word is expected.One point needs your call: should single-command mode accept the output switches (
-o,--verbose) at all? TodayParseArgsparses them but leaves them in the command text, soragflow-cli -o json ws lsfails withexpected command, got -.-h/-t/-u/-p/-f/-k.-o/--verboseas the only global switches and strip them from the command text, so an agent can ask for JSON.I will align #22650 with whichever you prefer; if it is (1) I will also make the connection flags fail with that message instead of being parsed.
ccclucky commentedon Nov 25, 2026
Implemented in #22650 at
7194b50be, following your direction:rf.ymlonly.-h/-t/-u/-p/-f/-kare rejected withsingle-command mode reads its settings from rf.yml; <flag> is not accepted, so-fcan no longer point at another file and-u/-pno longer trigger an interactive login.-o/--output,-v/--verbose,--helpand--versionremain global switches and are stripped, since your example showsragflow-cli -o json ws lsas the agent-facing form; say the word if you would rather reject those too and I will drop them.ws/ws deletereach their handlers, and reserved words parse as names and one-word questions.Verification (local, CGO_ENABLED=0):
go test -count=1 ./internal/cli/→ ok;go vet ./internal/cli/→ clean. Binary checks:ragflow-cli -f rf.yml ls datasets→ the rf.yml rejection, exit 1;ragflow-cli -o json ws ls→ command runs; bareragflow-cli→RAGFlow(user)>REPL.The help text and PR description now document the single-command rule instead of the old
-f rf.yml ...examples.