@@ -74,7 +74,9 @@ func setLog() {
74
74
func initConfig () {
75
75
76
76
home , err := os .UserHomeDir ()
77
- cobra .CheckErr (err )
77
+ if err != nil {
78
+ log .Fatal ("Error getting user home directory:" , err )
79
+ }
78
80
configPath := filepath .Join (home , ".local" , "gopt" )
79
81
80
82
if _ , err := os .Stat (configPath ); os .IsNotExist (err ) {
@@ -97,9 +99,9 @@ func initConfig() {
97
99
viper .SetDefault ("token" , false )
98
100
viper .SetDefault ("system_message" , config .DefaultSystemMsg )
99
101
viper .SetDefault ("max_token" , config .DefaultMaxToken )
100
- err := viper .SafeWriteConfigAs ( filepath . Join ( configPath , "config.yaml" ))
101
- cobra . CheckErr ( err )
102
-
102
+ if err := viper .SafeWriteConfig (); err != nil {
103
+ log . Fatal ( "Error creating config file:" , err )
104
+ }
103
105
} else {
104
106
// Config file was found but another error was produced
105
107
log .Fatalf ("Fatal error config file: %v" , err )
@@ -111,8 +113,10 @@ func initConfig() {
111
113
var apiKey string
112
114
fmt .Scanln (& apiKey )
113
115
viper .Set ("openai_api_key" , apiKey )
114
- err := viper .WriteConfig ()
115
- cobra .CheckErr (err )
116
+ if err := viper .WriteConfig (); err != nil {
117
+ log .Fatal ("Error writing config file:" , err )
118
+ }
119
+
116
120
}
117
121
118
122
// init variables
0 commit comments