Skip to content

Commit

Permalink
chore: use log.fatal
Browse files Browse the repository at this point in the history
  • Loading branch information
nicewook committed Nov 28, 2023
1 parent 365de72 commit 2673e0f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ func setLog() {
func initConfig() {

home, err := os.UserHomeDir()
cobra.CheckErr(err)
if err != nil {
log.Fatal("Error getting user home directory:", err)
}
configPath := filepath.Join(home, ".local", "gopt")

if _, err := os.Stat(configPath); os.IsNotExist(err) {
Expand All @@ -97,9 +99,9 @@ func initConfig() {
viper.SetDefault("token", false)
viper.SetDefault("system_message", config.DefaultSystemMsg)
viper.SetDefault("max_token", config.DefaultMaxToken)
err := viper.SafeWriteConfigAs(filepath.Join(configPath, "config.yaml"))
cobra.CheckErr(err)

if err := viper.SafeWriteConfig(); err != nil {
log.Fatal("Error creating config file:", err)
}
} else {
// Config file was found but another error was produced
log.Fatalf("Fatal error config file: %v", err)
Expand All @@ -111,8 +113,10 @@ func initConfig() {
var apiKey string
fmt.Scanln(&apiKey)
viper.Set("openai_api_key", apiKey)
err := viper.WriteConfig()
cobra.CheckErr(err)
if err := viper.WriteConfig(); err != nil {
log.Fatal("Error writing config file:", err)
}

}

// init variables
Expand Down

0 comments on commit 2673e0f

Please sign in to comment.