Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
kardolus
GitHub Repository: kardolus/chatgpt-cli
Path: blob/main/vendor/github.com/spf13/viper/finder.go
2875 views
1
package viper
2
3
import (
4
"errors"
5
6
"github.com/spf13/afero"
7
)
8
9
// WithFinder sets a custom [Finder].
10
func WithFinder(f Finder) Option {
11
return optionFunc(func(v *Viper) {
12
if f == nil {
13
return
14
}
15
16
v.finder = f
17
})
18
}
19
20
// Finder looks for files and directories in an [afero.Fs] filesystem.
21
type Finder interface {
22
Find(fsys afero.Fs) ([]string, error)
23
}
24
25
// Finders combines multiple finders into one.
26
func Finders(finders ...Finder) Finder {
27
return &combinedFinder{finders: finders}
28
}
29
30
// combinedFinder is a Finder that combines multiple finders.
31
type combinedFinder struct {
32
finders []Finder
33
}
34
35
// Find implements the [Finder] interface.
36
func (c *combinedFinder) Find(fsys afero.Fs) ([]string, error) {
37
var results []string
38
var errs []error
39
40
for _, finder := range c.finders {
41
if finder == nil {
42
continue
43
}
44
45
r, err := finder.Find(fsys)
46
if err != nil {
47
errs = append(errs, err)
48
continue
49
}
50
51
results = append(results, r...)
52
}
53
54
return results, errors.Join(errs...)
55
}
56
57