initConfig reads in config file and ENV variables if set.
()
| 47 | |
| 48 | // initConfig reads in config file and ENV variables if set. |
| 49 | func initConfig() { |
| 50 | if cfgFile != "" { |
| 51 | // Use config file from the flag. |
| 52 | viper.SetConfigFile(cfgFile) |
| 53 | } else { |
| 54 | // Find home directory. |
| 55 | home, err := homedir.Dir() |
| 56 | if err != nil { |
| 57 | fmt.Println(err) |
| 58 | os.Exit(1) |
| 59 | } |
| 60 | |
| 61 | // Search config in home directory with name ".capipe" (without extension). |
| 62 | viper.AddConfigPath(home) |
| 63 | viper.SetConfigName(".capipe") |
| 64 | } |
| 65 | |
| 66 | viper.AutomaticEnv() // read in environment variables that match |
| 67 | |
| 68 | // If a config file is found, read it in. |
| 69 | if err := viper.ReadInConfig(); err == nil { |
| 70 | fmt.Println("Using config file:", viper.ConfigFileUsed()) |
| 71 | } |
| 72 | } |
nothing calls this directly
no outgoing calls
no test coverage detected