Skip to content

Commit

Permalink
executor now logs commands stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
gweebg committed Feb 20, 2024
1 parent df6c006 commit 10ccffd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func main() {

configFlags["exec"] = flag.Bool(
"exec",
true,
false,
"enable execution of configuration defined actions",
)

Expand Down
9 changes: 9 additions & 0 deletions internal/watcher/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)

Expand All @@ -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 {
Expand Down

0 comments on commit 10ccffd

Please sign in to comment.