From 065797b047573637c09af771055c723c8b00ecd9 Mon Sep 17 00:00:00 2001 From: Hz_ Date: Wed, 17 Jun 2026 20:21:42 +0800 Subject: [PATCH] Refactor(go-cli): improve variable and label naming in CLI parseAddModel (#16145) ### What problem does this PR solve? This PR improves code readability in the CLI parser by renaming the loop index `i` to `modelIndex`. It also renames the loop label `A` to `optionsLoop` to align with standard Go naming conventions. ### Type of change - [x] Refactoring --- internal/cli/user_parser.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/internal/cli/user_parser.go b/internal/cli/user_parser.go index c98b2d5f10..b004a459ce 100644 --- a/internal/cli/user_parser.go +++ b/internal/cli/user_parser.go @@ -942,7 +942,7 @@ func (p *Parser) parseAddModel() (*Command, error) { } p.nextToken() - i := 0 + modelIndex := 0 var modelTypes []string var supportThink *bool = nil maxTokens := 0 @@ -955,15 +955,16 @@ func (p *Parser) parseAddModel() (*Command, error) { } p.nextToken() -A: +optionsLoop: for { - if i >= len(modelNames) { + if modelIndex >= len(modelNames) { return nil, fmt.Errorf("too many model configs: got more configs than model names") } + currentModelName := modelNames[modelIndex] switch p.curToken.Type { case TokenThink: if supportThink != nil { - return nil, fmt.Errorf("think model is already set for model %s", modelNames[i]) + return nil, fmt.Errorf("think model is already set for model %s", currentModelName) } value := true supportThink = &value @@ -1022,7 +1023,7 @@ A: case TokenToken, TokenTokens: p.nextToken() if maxTokens != 0 { - return nil, fmt.Errorf("max tokens is already given %d for model %s", maxTokens, modelNames[i]) + return nil, fmt.Errorf("max tokens is already given %d for model %s", maxTokens, currentModelName) } if p.curToken.Type != TokenInteger { return nil, fmt.Errorf("expected integer") @@ -1036,7 +1037,7 @@ A: case TokenComma, TokenSemicolon, TokenEOF: if len(modelTypes) == 0 { - return nil, fmt.Errorf("model type is required for model %s", modelNames[i]) + return nil, fmt.Errorf("model type is required for model %s", currentModelName) } seenTypes := make(map[string]struct{}, len(modelTypes)) @@ -1058,11 +1059,11 @@ A: modelTypes = dedupedModelTypes if len(modelTypes) == 0 { - return nil, fmt.Errorf("model type is required for model %s", modelNames[i]) + return nil, fmt.Errorf("model type is required for model %s", currentModelName) } model := map[string]any{ - "model_name": modelNames[i], + "model_name": currentModelName, "model_types": modelTypes, "max_tokens": maxTokens, } @@ -1077,7 +1078,7 @@ A: models = append(models, model) - i++ + modelIndex++ modelTypes = nil supportThink = nil maxTokens = 0 @@ -1092,7 +1093,7 @@ A: if p.curToken.Type == TokenSemicolon { p.nextToken() } - break A + break optionsLoop default: return nil, fmt.Errorf("unexpected token type: %s", p.curToken.Value)