-
Notifications
You must be signed in to change notification settings - Fork 27
/
main.go
59 lines (49 loc) · 1.17 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"flag"
"fmt"
"github.com/ezekg/git-hound/Godeps/_workspace/src/github.com/fatih/color"
"github.com/ezekg/git-hound/Godeps/_workspace/src/sourcegraph.com/sourcegraph/go-diff/diff"
"os"
)
func main() {
var (
noColor = flag.Bool("no-color", false, "Disable color output")
config = flag.String("config", ".githound.yml", "Hound config file")
bin = flag.String("bin", "git", "Executable binary to use for git command")
)
flag.Parse()
if *noColor {
color.NoColor = true
}
hound := &Hound{Config: *config}
git := &Command{Bin: *bin}
if ok, _ := hound.New(); ok {
out, _ := git.Exec("diff", "-U0", "--staged")
fileDiffs, err := diff.ParseMultiFileDiff([]byte(out))
if err != nil {
fmt.Print(err)
os.Exit(1)
}
for _, fileDiff := range fileDiffs {
fileName := fileDiff.NewName
hunks := fileDiff.GetHunks()
errs := make(chan error)
go func() {
for _, hunk := range hunks {
errs <- hound.Sniff(fileName, hunk)
}
close(errs)
}()
for err := range errs {
if err != nil {
fmt.Print(err)
os.Exit(1)
}
}
}
}
out, code := git.Exec(flag.Args()...)
fmt.Print(out)
os.Exit(code)
}