grokkit/cmd/commitmsg.go

33 lines
773 B
Go
Raw Permalink Normal View History

2026-02-28 18:03:12 +00:00
package cmd
2026-02-28 18:28:27 +00:00
2026-02-28 19:56:23 +00:00
import (
"github.com/fatih/color"
"github.com/spf13/cobra"
"gmgauthier.com/grokkit/config"
2026-02-28 19:56:23 +00:00
)
2026-02-28 18:28:27 +00:00
var commitMsgCmd = &cobra.Command{
Use: "commit-msg",
Short: "Generate conventional commit message from staged changes",
Run: runCommitMsg,
}
func runCommitMsg(cmd *cobra.Command, args []string) {
diff, err := gitRun([]string{"diff", "--cached", "--no-color"})
if err != nil {
color.Red("Failed to get staged changes: %v", err)
return
}
if diff == "" {
color.Yellow("No staged changes!")
return
}
modelFlag, _ := cmd.Flags().GetString("model")
model := config.GetModel("commitmsg", modelFlag)
client := newGrokClient()
messages := buildCommitMessages(diff)
color.Yellow("Generating commit message...")
client.Stream(messages, model)
}