Skip to content

Commit

Permalink
Bail early when provided model name for 'run' is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
cheshire137 committed Oct 8, 2024
1 parent 5ebf021 commit 1e92fd9
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions cmd/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/cli/go-gh/v2/pkg/term"
"github.com/github/gh-models/internal/azure_models"
"github.com/github/gh-models/internal/ux"
"github.com/github/gh-models/pkg/util"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -226,15 +227,11 @@ func NewRunCommand() *cobra.Command {
modelName = args[0]
}

for _, model := range models {
if strings.EqualFold(model.FriendlyName, modelName) || strings.EqualFold(model.Name, modelName) {
modelName = model.Name
break
}
}

if modelName == "" {
return errors.New("the specified model name is not supported")
validModelName := util.GetValidModelName(modelName, models)
if validModelName == nil {
return fmt.Errorf("the specified model name is not supported: %s", modelName)
} else {
modelName = *validModelName
}

initialPrompt := ""
Expand Down

0 comments on commit 1e92fd9

Please sign in to comment.