-
Notifications
You must be signed in to change notification settings - Fork 10
/
glob.go
27 lines (22 loc) · 857 Bytes
/
glob.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package glob
import (
"fmt"
"github.com/simplesurance/baur/v2/internal/fs"
)
// Resolver resolves a glob path to files. The functionality is the same then
// filepath.Glob() with the addition that '**' is supported to match files
// directories recursively.
type Resolver struct{}
// Resolve resolves the globPath to absolute file paths.
// Files are resolved in the same way then filepath.Glob() does, with 2 Exceptions:
// - it also supports '**' to match files and directories recursively,
// - it only returns paths to files, no directory paths,
// If a globPath doesn't match any files an empty []string is returned and
// error is nil
func (r *Resolver) Resolve(globPath string) ([]string, error) {
paths, err := fs.FileGlob(globPath)
if err != nil {
return nil, fmt.Errorf("resolving %q failed: %w", globPath, err)
}
return paths, nil
}