From df708667891a1379b2fb0f0d16389aa1be420e72 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Tue, 4 Jun 2024 15:28:21 +0200 Subject: [PATCH] refactor: move old config search code Signed-off-by: Mark Sagi-Kazar --- file.go | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/file.go b/file.go index 5f8a22c..d52f018 100644 --- a/file.go +++ b/file.go @@ -16,21 +16,7 @@ func ExperimentalFinder() Option { }) } -func (v *Viper) findConfigFileWithFinder(finder Finder) (string, error) { - results, err := finder.Find(v.fs) - if err != nil { - return "", err - } - - if len(results) == 0 { - return "", ConfigFileNotFoundError{v.configName, fmt.Sprintf("%s", v.configPaths)} - } - - return results[0], nil -} - -// Search all configPaths for any config file. -// Returns the first path that exists (and is a config file). +// Search for a config file. func (v *Viper) findConfigFile() (string, error) { finder := v.finder @@ -54,6 +40,25 @@ func (v *Viper) findConfigFile() (string, error) { return v.findConfigFileWithFinder(finder) } + return v.findConfigFileOld() +} + +func (v *Viper) findConfigFileWithFinder(finder Finder) (string, error) { + results, err := finder.Find(v.fs) + if err != nil { + return "", err + } + + if len(results) == 0 { + return "", ConfigFileNotFoundError{v.configName, fmt.Sprintf("%s", v.configPaths)} + } + + return results[0], nil +} + +// Search all configPaths for any config file. +// Returns the first path that exists (and is a config file). +func (v *Viper) findConfigFileOld() (string, error) { v.logger.Info("searching for config in paths", "paths", v.configPaths) for _, cp := range v.configPaths {