package cli import ( "fmt" "os" "github.com/spf13/viper" ) // InitConfig initializes viper configuration func InitConfig(cfgFile string) { if cfgFile != "" { // Use config file from the flag viper.SetConfigFile(cfgFile) } else { // Find home directory home, err := os.UserHomeDir() if err != nil { fmt.Fprintf(os.Stderr, "Error getting home directory: %v\n", err) return } // Search config in home directory with name ".totalrecall" (without extension) viper.AddConfigPath(home) viper.AddConfigPath(".") viper.SetConfigType("yaml") viper.SetConfigName(".totalrecall") } // Environment variables viper.SetEnvPrefix("TOTALRECALL") viper.AutomaticEnv() // Read config file if err := viper.ReadInConfig(); err == nil { fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed()) } }