66
77 "github.com/atotto/clipboard"
88 "github.com/dfanso/commit-msg/src/chatgpt"
9+ "github.com/dfanso/commit-msg/src/claude"
910 "github.com/dfanso/commit-msg/src/gemini"
1011 "github.com/dfanso/commit-msg/src/grok"
1112 "github.com/dfanso/commit-msg/src/internal/display"
@@ -17,30 +18,34 @@ import (
1718
1819// main is the entry point of the commit message generator
1920func main () {
20- // Get API key from environment variables
21- var apiKey string
22- if os .Getenv ("COMMIT_LLM" ) == "google" {
23- apiKey = os .Getenv ("GOOGLE_API_KEY" )
24- if apiKey == "" {
25- log .Fatalf ("GOOGLE_API_KEY is not set" )
26- }
27- } else if os .Getenv ("COMMIT_LLM" ) == "grok" {
28- apiKey = os .Getenv ("GROK_API_KEY" )
29- if apiKey == "" {
30- log .Fatalf ("GROK_API_KEY is not set" )
31- }
32- } else if os .Getenv ("COMMIT_LLM" ) == "chatgpt" {
33- apiKey = os .Getenv ("OPENAI_API_KEY" )
34- if apiKey == "" {
35- log .Fatalf ("OPENAI_API_KEY is not set" )
36- }
37- } else if os .Getenv ("COMMIT_LLM" ) == "claude" {
38- apiKey = os .Getenv ("CLAUDE_API_KEY" )
39- if apiKey == "" {
40- log .Fatalf ("CLAUDE_API_KEY is not set" )
41- } else {
42- log .Fatalf ("Invalid COMMIT_LLM value: %s" , os .Getenv ("COMMIT_LLM" ))
43- }
21+ // Validate COMMIT_LLM and required API keys
22+ commitLLM := os .Getenv ("COMMIT_LLM" )
23+ var apiKey string
24+
25+ switch commitLLM {
26+ case "google" :
27+ apiKey = os .Getenv ("GOOGLE_API_KEY" )
28+ if apiKey == "" {
29+ log .Fatalf ("GOOGLE_API_KEY is not set" )
30+ }
31+ case "grok" :
32+ apiKey = os .Getenv ("GROK_API_KEY" )
33+ if apiKey == "" {
34+ log .Fatalf ("GROK_API_KEY is not set" )
35+ }
36+ case "chatgpt" :
37+ apiKey = os .Getenv ("OPENAI_API_KEY" )
38+ if apiKey == "" {
39+ log .Fatalf ("OPENAI_API_KEY is not set" )
40+ }
41+ case "claude" :
42+ apiKey = os .Getenv ("CLAUDE_API_KEY" )
43+ if apiKey == "" {
44+ log .Fatalf ("CLAUDE_API_KEY is not set" )
45+ }
46+ default :
47+ log .Fatalf ("Invalid COMMIT_LLM value: %s" , commitLLM )
48+ }
4449
4550 // Get current directory
4651 currentDir , err := os .Getwd ()
@@ -111,6 +116,8 @@ func main() {
111116 commitMsg , err = gemini .GenerateCommitMessage (config , changes , apiKey )
112117 } else if os .Getenv ("COMMIT_LLM" ) == "chatgpt" {
113118 commitMsg , err = chatgpt .GenerateCommitMessage (config , changes , apiKey )
119+ } else if os .Getenv ("COMMIT_LLM" ) == "claude" {
120+ commitMsg , err = claude .GenerateCommitMessage (config , changes , apiKey )
114121 } else {
115122 commitMsg , err = grok .GenerateCommitMessage (config , changes , apiKey )
116123 }
@@ -139,5 +146,4 @@ func main() {
139146
140147 // Display changes preview
141148 display .ShowChangesPreview (fileStats )
142- }
143149}
0 commit comments