all repos — erl @ 5756d6ee93062edeb2e19af551811a68aea9f333

Execute Reload Loop

feat: enable watching extra paths with -w/--watch

Alin
commit

5756d6ee93062edeb2e19af551811a68aea9f333

parent

d30b683684be3a8e626d0202d61284afa7696364

2 files changed, 16 insertions(+), 8 deletions(-)

changed files
M README.mdREADME.md
@@ -37,6 +37,7 @@
- `--exec string` - Command to execute on file change (optional, defaults to "go run") - `--quiet` - Suppress erl's own output - `--verbose` - Enable verbose output (print file events) +- `--watch path` - Add extra paths to watch (recursive) ### Examples
M main.gomain.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 {