diff --git a/cmd/root.go b/cmd/root.go index d5c77e4..29f25b3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -64,14 +64,24 @@ func initConfig() { // Search config in the current directory with name "member-console.yaml" viper.AddConfigPath(".") viper.SetConfigType("yaml") - viper.SetConfigName("member-console") + viper.SetConfigName("mc-config") // Use "mc-config" as the config file name } - viper.SetEnvPrefix("WCMC") // set environment variable prefix - viper.AutomaticEnv() // read in environment variables that match + viper.SetEnvPrefix("MC") // set environment variable prefix + viper.AutomaticEnv() // read in environment variables that match // If a config file is found, read it in. - if err := viper.ReadInConfig(); err == nil { + if err := viper.ReadInConfig(); err != nil { + if _, ok := err.(viper.ConfigFileNotFoundError); ok { + // Config file not found. This is always an error. + fmt.Fprintln(os.Stderr, "Error: Config file not found:", err) + os.Exit(1) + } else { + // Another error occurred (e.g., malformed YAML). This should be reported. + fmt.Fprintln(os.Stderr, "Error reading config file:", err) + os.Exit(1) // Exit for other config read errors + } + } else { fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed()) } }