MCPcopy Index your code
hub / github.com/devopsctl/gitlabctl / initConfig

Function initConfig

cmd/root.go:85–111  ·  view source on GitHub ↗

initConfig reads in config file and ENV variables if set.

()

Source from the content-addressed store, hash-verified

83
84// initConfig reads in config file and ENV variables if set.
85func initConfig() {
86 if cfgFile != "" {
87 // Use config file from the flag.
88 viper.SetConfigFile(cfgFile)
89 } else {
90 // Find home directory.
91 home, err := homedir.Dir()
92 if err != nil {
93 er(err)
94 }
95
96 // Search config in home directory with name ".gitlabctl" (without extension).
97 viper.AddConfigPath(home)
98 viper.SetConfigName(".gitlabctl")
99 }
100
101 viper.AutomaticEnv() // read in environment variables that match
102
103 // If a config file is found, read it in.
104 if err := viper.ReadInConfig(); err != nil {
105 // NOTE: the config file is not required to exists
106 // raise an error if error is other than config file not found
107 if !strings.Contains(err.Error(), `Config File ".gitlabctl" Not Found`) {
108 er(err)
109 }
110 }
111}

Callers

nothing calls this directly

Calls 1

erFunction · 0.85

Tested by

no test coverage detected