cleanup / add err handling
This commit is contained in:
parent
49f4067bc5
commit
3f502dba81
2 changed files with 5 additions and 21 deletions
|
|
@ -3,8 +3,6 @@ package dirutil
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/bmatcuk/doublestar/v4"
|
"github.com/bmatcuk/doublestar/v4"
|
||||||
"io/fs"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func matchesAny(patterns []string, path string) bool {
|
func matchesAny(patterns []string, path string) bool {
|
||||||
|
|
@ -31,20 +29,3 @@ func IsGlobMatch(path string, patterns []string, excludePatterns []string) bool
|
||||||
}
|
}
|
||||||
return matchesAny(patterns, path)
|
return matchesAny(patterns, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GlobMatchDirs(root string, includePatterns, excludePatterns []string, cb func(string)) {
|
|
||||||
//directories := map[string]bool{}
|
|
||||||
// Walk through the directory recursively
|
|
||||||
_ = filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if matchesAny(excludePatterns, path) {
|
|
||||||
return fs.SkipDir
|
|
||||||
}
|
|
||||||
if matchesAny(includePatterns, path) {
|
|
||||||
cb(path)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
)
|
)
|
||||||
|
|
@ -45,9 +46,11 @@ func FromConfigFile(workingDir string) *ProjectConfig {
|
||||||
bytes, err := os.ReadFile(filePath)
|
bytes, err := os.ReadFile(filePath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = yaml.Unmarshal(bytes, cfg)
|
err = yaml.Unmarshal(bytes, cfg)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
return cfg.EnhanceWithDefaults()
|
slog.Error("Error parsing config file", slog.String("file", filePath), slog.String("error", err.Error()))
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
return cfg.EnhanceWithDefaults()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue