From 10ccffd66ce4709090a1b09310de2f53696430a9 Mon Sep 17 00:00:00 2001 From: guilherme Date: Tue, 20 Feb 2024 10:09:19 +0000 Subject: [PATCH] executor now logs commands stdout --- Makefile | 2 +- cmd/watch.go | 2 +- internal/watcher/executor.go | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 033bfae..b1936fd 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ CMD_FILES := $(wildcard cmd/*.go) BINARIES := $(patsubst cmd/%.go,$(BUILD_FOLDER)/%.run,$(CMD_FILES)) # Build targets -all: $(BINARIES) +all: clean $(BINARIES) $(BUILD_FOLDER)/%.run: cmd/%.go @mkdir -p $(BUILD_FOLDER) diff --git a/cmd/watch.go b/cmd/watch.go index 1d66a36..c26f99c 100644 --- a/cmd/watch.go +++ b/cmd/watch.go @@ -27,7 +27,7 @@ func main() { configFlags["exec"] = flag.Bool( "exec", - true, + false, "enable execution of configuration defined actions", ) diff --git a/internal/watcher/executor.go b/internal/watcher/executor.go index cee4943..5893632 100644 --- a/internal/watcher/executor.go +++ b/internal/watcher/executor.go @@ -71,6 +71,7 @@ func (e *Executor) Execute(action config.Exec) { args := strings.Split(action.Args, " ") args = append([]string{action.Path}, args...) + // args = append([]string{"-u"}, args...) // todo: change action formats cmd := exec.CommandContext(ctx, action.Type, args...) @@ -83,6 +84,14 @@ func (e *Executor) Execute(action config.Exec) { } }() + stdout, _ := cmd.StdoutPipe() + go func() { + scanner := bufio.NewScanner(stdout) + for scanner.Scan() { + e.logger.Debug().Str("command", action.String()).Msg(scanner.Text()) + } + }() + // redirecting the stderr of the spawned process to the pipe for later logging stderr, _ := cmd.StderrPipe() if err := cmd.Start(); err != nil {