Skip to content

Commit

Permalink
read read .yml file only when using default config path
Browse files Browse the repository at this point in the history
  • Loading branch information
Codelax committed Dec 14, 2022
1 parent 2552bb8 commit 40da420
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions scw/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,21 @@ func LoadConfig() (*Config, error) {
configPath := GetConfigPath()
cfg, err := LoadConfigFromPath(configPath)

var configNotFoundError *ConfigFileNotFoundError
if err != nil && goerrors.As(err, &configNotFoundError) && strings.HasSuffix(configPath, ".yaml") {
configPath = strings.TrimSuffix(configPath, ".yaml") + ".yml"
cfgYml, errYml := LoadConfigFromPath(configPath)
// If .yml config is not found, return first error when reading .yaml
if errYml == nil || (errYml != nil && !goerrors.As(errYml, &configNotFoundError)) {
return cfgYml, errYml
// Special case if using default config path
// if config.yaml does not exist, we should try to read config.yml
if os.Getenv(ScwConfigPathEnv) == "" {
var configNotFoundError *ConfigFileNotFoundError
if err != nil && goerrors.As(err, &configNotFoundError) && strings.HasSuffix(configPath, ".yaml") {
configPath = strings.TrimSuffix(configPath, ".yaml") + ".yml"
cfgYml, errYml := LoadConfigFromPath(configPath)
// If .yml config is not found, return first error when reading .yaml
if errYml == nil || (errYml != nil && !goerrors.As(errYml, &configNotFoundError)) {
return cfgYml, errYml
}
}
}
return cfg, err

return cfg, err
}

// LoadConfigFromPath read the config from the given path.
Expand Down

0 comments on commit 40da420

Please sign in to comment.