From 4dddf7c62e16bce5807744018f5b753bfe21bbd2 Mon Sep 17 00:00:00 2001 From: Jeff Lindsay Date: Thu, 9 Nov 2017 14:57:16 -0600 Subject: [PATCH] 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 --- util.go | 5 +++-- viper.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/util.go b/util.go index 3ebada9..c784dad 100644 --- a/util.go +++ b/util.go @@ -24,6 +24,7 @@ import ( "github.com/hashicorp/hcl" "github.com/magiconair/properties" toml "github.com/pelletier/go-toml" + "github.com/spf13/afero" "github.com/spf13/cast" jww "github.com/spf13/jwalterweatherman" "gopkg.in/yaml.v2" @@ -121,8 +122,8 @@ func absPathify(inPath string) string { } // Check if File / Directory Exists -func exists(path string) (bool, error) { - _, err := v.fs.Stat(path) +func exists(fs afero.Fs, path string) (bool, error) { + _, err := fs.Stat(path) if err == nil { return true, nil } diff --git a/viper.go b/viper.go index 963861a..64f006a 100644 --- a/viper.go +++ b/viper.go @@ -1537,7 +1537,7 @@ func (v *Viper) searchInPath(in string) (filename string) { jww.DEBUG.Println("Searching for config in ", in) for _, ext := range SupportedExts { 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)) return filepath.Join(in, v.configName+"."+ext) }