mirror of
https://github.com/nvms/esr.git
synced 2025-12-16 14:40:53 +00:00
33 lines
610 B
Go
33 lines
610 B
Go
package glob
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/bmatcuk/doublestar/v3"
|
|
)
|
|
|
|
func GlobFiles(pattern string) ([]string, error) {
|
|
cwd, err := os.Getwd()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to get current working directory: %w", err)
|
|
}
|
|
|
|
matches, err := doublestar.Glob(filepath.Join(cwd, pattern))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to match pattern: %w", err)
|
|
}
|
|
|
|
for i, match := range matches {
|
|
matches[i] = strings.TrimPrefix(match, cwd)
|
|
}
|
|
|
|
for i, match := range matches {
|
|
matches[i] = strings.TrimPrefix(match, "/")
|
|
}
|
|
|
|
return matches, nil
|
|
}
|