LoadConfig loads a config file from a given scope. The returned Config, contains exclusively information from the given scope. If it couldn't find a config file to the given scope, an empty one is returned.
(scope Scope)
| 161 | // contains exclusively information from the given scope. If it couldn't find a |
| 162 | // config file to the given scope, an empty one is returned. |
| 163 | func LoadConfig(scope Scope) (*Config, error) { |
| 164 | if scope == LocalScope { |
| 165 | return nil, fmt.Errorf("LocalScope should be read from the a ConfigStorer") |
| 166 | } |
| 167 | |
| 168 | files, err := Paths(scope) |
| 169 | if err != nil { |
| 170 | return nil, err |
| 171 | } |
| 172 | |
| 173 | for _, file := range files { |
| 174 | f, err := osfs.Default.Open(file) |
| 175 | if err != nil { |
| 176 | if os.IsNotExist(err) { |
| 177 | continue |
| 178 | } |
| 179 | |
| 180 | return nil, err |
| 181 | } |
| 182 | |
| 183 | defer f.Close() |
| 184 | return ReadConfig(f) |
| 185 | } |
| 186 | |
| 187 | return NewConfig(), nil |
| 188 | } |
| 189 | |
| 190 | // Paths returns the config file location for a given scope. |
| 191 | func Paths(scope Scope) ([]string, error) { |