mirror of
https://git.sr.ht/~rjarry/aerc
synced 2025-02-23 07:53:59 +01:00

Currently the only feedback we have from hooks is the error code. Log STDOUT on loglevel TRACE and log STDERR on loglevel ERROR if the command exists with an error. Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Robin Jarry <robin@jarry.cc>
31 lines
583 B
Go
31 lines
583 B
Go
package hooks
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"os/exec"
|
|
|
|
"git.sr.ht/~rjarry/aerc/lib/log"
|
|
)
|
|
|
|
func RunHook(h HookType) error {
|
|
cmd := h.Cmd()
|
|
if cmd == "" {
|
|
return nil
|
|
}
|
|
env := h.Env()
|
|
log.Debugf("hooks: running command %q (env %v)", cmd, env)
|
|
|
|
proc := exec.Command("sh", "-c", cmd)
|
|
var outb, errb bytes.Buffer
|
|
proc.Stdout = &outb
|
|
proc.Stderr = &errb
|
|
proc.Env = os.Environ()
|
|
proc.Env = append(proc.Env, env...)
|
|
err := proc.Run()
|
|
log.Tracef("hooks: %q stdout: %s", cmd, outb.String())
|
|
if err != nil {
|
|
log.Errorf("hooks:%q stderr: %s", cmd, errb.String())
|
|
}
|
|
return err
|
|
}
|