mirror of
https://github.com/spf13/viper
synced 2024-12-23 12:07:02 +00:00
#73 Avoid searching CWD if no config in provided dirs
This commit is contained in:
parent
d62d4bb4c6
commit
3f164ab4ca
1 changed files with 6 additions and 2 deletions
8
viper.go
8
viper.go
|
@ -50,7 +50,7 @@ type UnsupportedConfigError string
|
|||
|
||||
// Returns the formatted configuration error.
|
||||
func (str UnsupportedConfigError) Error() string {
|
||||
return fmt.Sprintf("Unsupported Config Type %q", string(str))
|
||||
return fmt.Sprintf("Unsupported Config Type %q or Config File Not Found", string(str))
|
||||
}
|
||||
|
||||
// Denotes encountering an unsupported remote
|
||||
|
@ -967,13 +967,17 @@ func (v *Viper) findConfigFile() (string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if len(v.configPaths) > 0 {
|
||||
return "", fmt.Errorf("Config file not found in: %s", v.configPaths)
|
||||
}
|
||||
|
||||
// try the current working directory
|
||||
wd, _ := os.Getwd()
|
||||
file := v.searchInPath(wd)
|
||||
if file != "" {
|
||||
return file, nil
|
||||
}
|
||||
return "", fmt.Errorf("config file not found in: %s", v.configPaths)
|
||||
return "", fmt.Errorf("config file not found in the current working directory %q", wd)
|
||||
}
|
||||
|
||||
// Prints all configuration registries for debugging
|
||||
|
|
Loading…
Reference in a new issue