aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hook.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/hook.go b/hook.go
index 67dbf6a..a5c84da 100644
--- a/hook.go
+++ b/hook.go
@@ -6,11 +6,14 @@ import (
"strings"
)
+type Hooker map[string]bool
+
func execHook(s string) error {
cmd := strings.Fields(s)
return exec.Command(cmd[0], cmd[1:]...).Run()
}
+/*
func NewHooker() chan string {
h := make(chan string, 2)
go func() {
@@ -22,3 +25,20 @@ func NewHooker() chan string {
}()
return h
}
+*/
+
+func NewHooker() Hooker {
+ return make(Hooker)
+}
+
+func (h Hooker) Notice(cmd string) {
+ h[cmd] = true
+}
+
+func (h Hooker) Execute() {
+ for cmd := range h {
+ if err := execHook(cmd); err != nil {
+ log.Println(cmd, err)
+ }
+ }
+}