Skip to content

Commit 2673e0f

Browse files
committed
chore: use log.fatal
1 parent 365de72 commit 2673e0f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

cmd/init.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ func setLog() {
7474
func initConfig() {
7575

7676
home, err := os.UserHomeDir()
77-
cobra.CheckErr(err)
77+
if err != nil {
78+
log.Fatal("Error getting user home directory:", err)
79+
}
7880
configPath := filepath.Join(home, ".local", "gopt")
7981

8082
if _, err := os.Stat(configPath); os.IsNotExist(err) {
@@ -97,9 +99,9 @@ func initConfig() {
9799
viper.SetDefault("token", false)
98100
viper.SetDefault("system_message", config.DefaultSystemMsg)
99101
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+
}
103105
} else {
104106
// Config file was found but another error was produced
105107
log.Fatalf("Fatal error config file: %v", err)
@@ -111,8 +113,10 @@ func initConfig() {
111113
var apiKey string
112114
fmt.Scanln(&apiKey)
113115
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+
116120
}
117121

118122
// init variables

0 commit comments

Comments
 (0)