11package cmd
22
33import (
4- "log"
54 "os"
65
76 "github.com/atotto/clipboard"
@@ -24,7 +23,8 @@ func CreateCommitMsg () {
2423 // Validate COMMIT_LLM and required API keys
2524 useLLM ,err := store .DefaultLLMKey ()
2625 if err != nil {
27- log .Fatal (err )
26+ pterm .Error .Printf ("No LLM configured. Run: commit llm setup\n " )
27+ os .Exit (1 )
2828 }
2929
3030 commitLLM := useLLM .LLM
@@ -34,12 +34,14 @@ func CreateCommitMsg () {
3434 // Get current directory
3535 currentDir , err := os .Getwd ()
3636 if err != nil {
37- log .Fatalf ("Failed to get current directory: %v" , err )
37+ pterm .Error .Printf ("Failed to get current directory: %v\n " , err )
38+ os .Exit (1 )
3839 }
3940
4041 // Check if current directory is a git repository
4142 if ! git .IsRepository (currentDir ) {
42- log .Fatalf ("Current directory is not a Git repository: %s" , currentDir )
43+ pterm .Error .Printf ("Current directory is not a Git repository: %s\n " , currentDir )
44+ os .Exit (1 )
4345 }
4446
4547 // Create a minimal config for the API
@@ -55,14 +57,15 @@ func CreateCommitMsg () {
5557 // Get file statistics before fetching changes
5658 fileStats , err := stats .GetFileStatistics (& repoConfig )
5759 if err != nil {
58- log .Fatalf ("Failed to get file statistics: %v" , err )
60+ pterm .Error .Printf ("Failed to get file statistics: %v\n " , err )
61+ os .Exit (1 )
5962 }
6063
6164 // Display header
6265 pterm .DefaultHeader .WithFullWidth ().
6366 WithBackgroundStyle (pterm .NewStyle (pterm .BgDarkGray )).
6467 WithTextStyle (pterm .NewStyle (pterm .FgLightWhite )).
65- Println ("🚀 Commit Message Generator" )
68+ Println ("Commit Message Generator" )
6669
6770 pterm .Println ()
6871
@@ -71,17 +74,26 @@ func CreateCommitMsg () {
7174
7275 if fileStats .TotalFiles == 0 {
7376 pterm .Warning .Println ("No changes detected in the Git repository." )
77+ pterm .Info .Println ("Tips:" )
78+ pterm .Info .Println (" - Stage your changes with: git add ." )
79+ pterm .Info .Println (" - Check repository status with: git status" )
80+ pterm .Info .Println (" - Make sure you're in the correct Git repository" )
7481 return
7582 }
7683
7784 // Get the changes
7885 changes , err := git .GetChanges (& repoConfig )
7986 if err != nil {
80- log .Fatalf ("Failed to get Git changes: %v" , err )
87+ pterm .Error .Printf ("Failed to get Git changes: %v\n " , err )
88+ os .Exit (1 )
8189 }
8290
8391 if len (changes ) == 0 {
8492 pterm .Warning .Println ("No changes detected in the Git repository." )
93+ pterm .Info .Println ("Tips:" )
94+ pterm .Info .Println (" - Stage your changes with: git add ." )
95+ pterm .Info .Println (" - Check repository status with: git status" )
96+ pterm .Info .Println (" - Make sure you're in the correct Git repository" )
8597 return
8698 }
8799
@@ -90,9 +102,10 @@ func CreateCommitMsg () {
90102 // Show generating spinner
91103 spinnerGenerating , err := pterm .DefaultSpinner .
92104 WithSequence ("⠋" , "⠙" , "⠹" , "⠸" , "⠼" , "⠴" , "⠦" , "⠧" , "⠇" , "⠏" ).
93- Start ("🤖 Generating commit message..." )
105+ Start ("Generating commit message with " + commitLLM + " ..." )
94106 if err != nil {
95- log .Fatalf ("Failed to start spinner: %v" , err )
107+ pterm .Error .Printf ("Failed to start spinner: %v\n " , err )
108+ os .Exit (1 )
96109 }
97110
98111 var commitMsg string
@@ -126,7 +139,19 @@ func CreateCommitMsg () {
126139
127140 if err != nil {
128141 spinnerGenerating .Fail ("Failed to generate commit message" )
129- log .Fatalf ("Error: %v" , err )
142+ switch commitLLM {
143+ case "Gemini" :
144+ pterm .Error .Printf ("Gemini API error. Check your GEMINI_API_KEY environment variable or run: commit llm setup\n " )
145+ case "OpenAI" :
146+ pterm .Error .Printf ("OpenAI API error. Check your OPENAI_API_KEY environment variable or run: commit llm setup\n " )
147+ case "Claude" :
148+ pterm .Error .Printf ("Claude API error. Check your CLAUDE_API_KEY environment variable or run: commit llm setup\n " )
149+ case "Grok" :
150+ pterm .Error .Printf ("Grok API error. Check your GROK_API_KEY environment variable or run: commit llm setup\n " )
151+ default :
152+ pterm .Error .Printf ("LLM API error: %v\n " , err )
153+ }
154+ os .Exit (1 )
130155 }
131156
132157 spinnerGenerating .Success ("✅ Commit message generated successfully!" )
0 commit comments