Skip to content

Commit

Permalink
fix: stucture for internal/hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
RaVbaker committed Jan 15, 2021
1 parent 499df40 commit b7140ed
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
25 changes: 0 additions & 25 deletions internal/hooks/hook.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package hooks

import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"

Expand Down Expand Up @@ -37,25 +34,3 @@ func (h *Hook) Definition() Spec {
}
return &NoopHook{}
}

type NoopHook struct{}

func (n NoopHook) Run(_ string) error {
return nil
}

type LocalHook struct {
Command string
}

func (l *LocalHook) Run(path string) error {
cmd := strings.ReplaceAll(l.Command, "{path}", path)
cmd = os.ExpandEnv(cmd)
fmt.Printf("> %s\n", cmd)
out, err := exec.Command("bash", "-c", cmd).CombinedOutput()
if err != nil {
return err
}
fmt.Println(string(out))
return nil
}
24 changes: 24 additions & 0 deletions internal/hooks/local_hook.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package hooks

import (
"fmt"
"os"
"os/exec"
"strings"
)

type LocalHook struct {
Command string
}

func (l *LocalHook) Run(path string) error {
cmd := strings.ReplaceAll(l.Command, "{path}", path)
cmd = os.ExpandEnv(cmd)
fmt.Printf("> %s\n", cmd)
out, err := exec.Command("bash", "-c", cmd).CombinedOutput()
if err != nil {
return err
}
fmt.Println(string(out))
return nil
}
7 changes: 7 additions & 0 deletions internal/hooks/noop_hook.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package hooks

type NoopHook struct{}

func (n NoopHook) Run(_ string) error {
return nil
}

0 comments on commit b7140ed

Please sign in to comment.