mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
a765ff8dcf
Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.19.0 to 1.20.1. - [Release notes](https://github.com/spf13/viper/releases) - [Commits](https://github.com/spf13/viper/compare/v1.19.0...v1.20.1) --- updated-dependencies: - dependency-name: github.com/spf13/viper dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
56 lines
1002 B
Go
56 lines
1002 B
Go
package viper
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/spf13/afero"
|
|
)
|
|
|
|
// WithFinder sets a custom [Finder].
|
|
func WithFinder(f Finder) Option {
|
|
return optionFunc(func(v *Viper) {
|
|
if f == nil {
|
|
return
|
|
}
|
|
|
|
v.finder = f
|
|
})
|
|
}
|
|
|
|
// Finder looks for files and directories in an [afero.Fs] filesystem.
|
|
type Finder interface {
|
|
Find(fsys afero.Fs) ([]string, error)
|
|
}
|
|
|
|
// Finders combines multiple finders into one.
|
|
func Finders(finders ...Finder) Finder {
|
|
return &combinedFinder{finders: finders}
|
|
}
|
|
|
|
// combinedFinder is a Finder that combines multiple finders.
|
|
type combinedFinder struct {
|
|
finders []Finder
|
|
}
|
|
|
|
// Find implements the [Finder] interface.
|
|
func (c *combinedFinder) Find(fsys afero.Fs) ([]string, error) {
|
|
var results []string
|
|
var errs []error
|
|
|
|
for _, finder := range c.finders {
|
|
if finder == nil {
|
|
continue
|
|
}
|
|
|
|
r, err := finder.Find(fsys)
|
|
if err != nil {
|
|
errs = append(errs, err)
|
|
continue
|
|
}
|
|
|
|
results = append(results, r...)
|
|
}
|
|
|
|
return results, errors.Join(errs...)
|
|
}
|