Repository navigation
Go CLI: fix model related commands - #16368
Conversation
Signed-off-by: Jin Hai <[email protected]>
📝 WalkthroughWalkthroughThe CLI parser now recognizes API-prefixed ChangesAPI show-provider command flow
Sequence Diagram(s)sequenceDiagram
participant parseAPIShowCommands
participant parseAPIShowProviderCommands
participant "api_show_provider commands"
participant ExecuteUserCommand
participant "CommonShowProvider handlers"
parseAPIShowCommands->>parseAPIShowProviderCommands: TokenProvider
parseAPIShowProviderCommands->>"api_show_provider commands": construct provider / instance / balance / model command
"api_show_provider commands"-->>ExecuteUserCommand: parsed command type
ExecuteUserCommand->>"CommonShowProvider handlers": dispatch
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
Signed-off-by: Jin Hai <[email protected]>
There was a problem hiding this comment.
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/user_parser.go`:
- Around line 677-680: The provider subcommand parsing in user_parser.go is too
permissive: the instance, balance, and model branches accept extra tokens after
the expected argument and still return successfully. Update the relevant parsing
paths in the provider subcommand handler to verify the next token is either an
optional semicolon or end-of-input, and raise a parse error for any unexpected
trailing token before returning from the instance/balance/model branches.
🪄 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: 68ed6dea-9299-43f4-8237-cf780fd4f606
📒 Files selected for processing (2)
internal/cli/cli_http.gointernal/cli/user_parser.go
| // Semicolon is optional | ||
| if p.curToken.Type == TokenSemicolon { | ||
| p.nextToken() | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Reject unexpected trailing tokens before returning provider subcommands.
The instance, balance, and model branches accept any non-semicolon token after the parsed argument, so malformed input like SHOW PROVIDER 'p' INSTANCE 'i' EXTRA still executes.
Suggested fix
// Semicolon is optional
if p.curToken.Type == TokenSemicolon {
p.nextToken()
+ } else if p.curToken.Type != TokenEOF {
+ return nil, fmt.Errorf("unexpected token after instance name: %s", p.curToken.Value)
}
return cmd, nil
}
@@
// Semicolon is optional
if p.curToken.Type == TokenSemicolon {
p.nextToken()
+ } else if p.curToken.Type != TokenEOF {
+ return nil, fmt.Errorf("unexpected token after balance: %s", p.curToken.Value)
}
return cmd, nil
}
@@
// Semicolon is optional
if p.curToken.Type == TokenSemicolon {
p.nextToken()
+ } else if p.curToken.Type != TokenEOF {
+ return nil, fmt.Errorf("unexpected token after model name: %s", p.curToken.Value)
}
return cmd, nil
}Also applies to: 692-695, 713-716
🤖 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/user_parser.go` around lines 677 - 680, The provider subcommand
parsing in user_parser.go is too permissive: the instance, balance, and model
branches accept extra tokens after the expected argument and still return
successfully. Update the relevant parsing paths in the provider subcommand
handler to verify the next token is either an optional semicolon or
end-of-input, and raise a parse error for any unexpected trailing token before
returning from the instance/balance/model branches.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16368 +/- ##
=======================================
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