cleanup / add err handling

This commit is contained in:
maddalax 2024-10-14 09:58:37 -05:00
parent 49f4067bc5
commit 3f502dba81
2 changed files with 5 additions and 21 deletions

View file

@ -3,8 +3,6 @@ package dirutil
import (
"fmt"
"github.com/bmatcuk/doublestar/v4"
"io/fs"
"path/filepath"
)
func matchesAny(patterns []string, path string) bool {
@ -31,20 +29,3 @@ func IsGlobMatch(path string, patterns []string, excludePatterns []string) bool
}
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
})
}

View file

@ -2,6 +2,7 @@ package config
import (
"gopkg.in/yaml.v3"
"log/slog"
"os"
"path"
)
@ -45,9 +46,11 @@ func FromConfigFile(workingDir string) *ProjectConfig {
bytes, err := os.ReadFile(filePath)
if err == nil {
err = yaml.Unmarshal(bytes, cfg)
if err == nil {
return cfg.EnhanceWithDefaults()
if err != nil {
slog.Error("Error parsing config file", slog.String("file", filePath), slog.String("error", err.Error()))
os.Exit(1)
}
return cfg.EnhanceWithDefaults()
}
}
}