mirror of
https://github.com/spf13/viper
synced 2024-12-22 19:47:01 +00:00
Allow exists util function to take afero.Fs so it can be used with non-deafult instances of Viper (#405)
Signed-off-by: Jeff Lindsay <progrium@gmail.com>
This commit is contained in:
parent
8ef37cbca7
commit
4dddf7c62e
2 changed files with 4 additions and 3 deletions
5
util.go
5
util.go
|
@ -24,6 +24,7 @@ import (
|
||||||
"github.com/hashicorp/hcl"
|
"github.com/hashicorp/hcl"
|
||||||
"github.com/magiconair/properties"
|
"github.com/magiconair/properties"
|
||||||
toml "github.com/pelletier/go-toml"
|
toml "github.com/pelletier/go-toml"
|
||||||
|
"github.com/spf13/afero"
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
jww "github.com/spf13/jwalterweatherman"
|
jww "github.com/spf13/jwalterweatherman"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
|
@ -121,8 +122,8 @@ func absPathify(inPath string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if File / Directory Exists
|
// Check if File / Directory Exists
|
||||||
func exists(path string) (bool, error) {
|
func exists(fs afero.Fs, path string) (bool, error) {
|
||||||
_, err := v.fs.Stat(path)
|
_, err := fs.Stat(path)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
2
viper.go
2
viper.go
|
@ -1537,7 +1537,7 @@ func (v *Viper) searchInPath(in string) (filename string) {
|
||||||
jww.DEBUG.Println("Searching for config in ", in)
|
jww.DEBUG.Println("Searching for config in ", in)
|
||||||
for _, ext := range SupportedExts {
|
for _, ext := range SupportedExts {
|
||||||
jww.DEBUG.Println("Checking for", filepath.Join(in, v.configName+"."+ext))
|
jww.DEBUG.Println("Checking for", filepath.Join(in, v.configName+"."+ext))
|
||||||
if b, _ := exists(filepath.Join(in, v.configName+"."+ext)); b {
|
if b, _ := exists(v.fs, filepath.Join(in, v.configName+"."+ext)); b {
|
||||||
jww.DEBUG.Println("Found: ", filepath.Join(in, v.configName+"."+ext))
|
jww.DEBUG.Println("Found: ", filepath.Join(in, v.configName+"."+ext))
|
||||||
return filepath.Join(in, v.configName+"."+ext)
|
return filepath.Join(in, v.configName+"."+ext)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue