diff options
-rw-r--r-- | hook.go | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -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) + } + } +} |