feat: apply ignores from .gitignore/.ignore files
1 file changed, 18 insertions(+), 3 deletions(-)
changed files
M main.go → main.go
@@ -3,6 +3,7 @@ import ( "context" "errors" + "fmt" "io" "log" "os"@@ -17,6 +18,7 @@ "github.com/fsnotify/fsnotify" "github.com/jessevdk/go-flags" "alin.ovh/erl/command" + "alin.ovh/erl/ignore" "alin.ovh/erl/state" "alin.ovh/erl/watcher" )@@ -127,11 +129,10 @@ args = slices.Insert(args, 0, "run") } } - watcher, err := watcher.New() + wd, err := os.Getwd() if err != nil { - log.Fatal(err) + log.Fatalf("failed to get working directory: %v", err) } - defer watcher.Close() ctx, cancel := signal.NotifyContext( context.Background(),@@ -140,6 +141,20 @@ syscall.SIGHUP, syscall.SIGTERM, ) defer cancel() + + filter := ignore.New(wd) + err = filter.ReadIgnoreFiles(ctx) + if err != nil { + panic(fmt.Sprintf("failed to read ignore files: %v", err)) + } + + watcher, err := watcher.New(watcher.Options{ + Filter: *filter, + }) + if err != nil { + panic(fmt.Sprintf("failed to create watcher: %v", err)) + } + defer watcher.Close() copts := command.Options{} if opts.Quiet {