feat: enable watching extra paths with -w/--watch
M main.go → main.go
@@ -24,9 +24,10 @@ "alin.ovh/erl/watcher" ) type Options struct { - Exec string `short:"x" long:"exec" description:"command to execute on file change"` - Quiet bool `short:"q" long:"quiet" description:"suppress own output"` - Verbose bool `short:"v" long:"verbose" description:"verbose output (print events)"` + Exec string `short:"x" long:"exec" description:"command to execute on file change"` + Quiet bool `short:"q" long:"quiet" description:"suppress own output"` + Verbose bool `short:"v" long:"verbose" description:"verbose output (print events)"` + Watch []string `short:"w" long:"watch" description:"extra directories to watch"` } func Start(ctx context.Context, verbose *log.Logger, w watcher.Watcher, sm *state.StateMachine) {@@ -90,11 +91,6 @@ log.Printf("Error: %v\n", err) } } }(w.Monitor()) - - err := w.AddRecursive(".") - if err != nil { - log.Fatalf("failed to add directory to watcher: %v", err) - } <-ctx.Done() log.Println("shutting down")@@ -155,6 +151,17 @@ if err != nil { panic(fmt.Sprintf("failed to create watcher: %v", err)) } defer watcher.Close() + + err = watcher.AddRecursive(".") + if err != nil { + log.Panicf("failed to add directory to watcher: %v", err) + } + for _, watchPath := range opts.Watch { + err = watcher.AddRecursive(watchPath) + if err != nil { + log.Panicf("failed to add directory to watcher: %v", err) + } + } copts := command.Options{} if opts.Quiet {