-
Notifications
You must be signed in to change notification settings - Fork 31
/
main.go
68 lines (52 loc) · 966 Bytes
/
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
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"os"
"sync"
"github.com/fatih/color"
)
func main() {
args, err := getArguments(nil)
if err != nil {
fail(err)
}
m := newMarkupFileFinder()
wg := sync.WaitGroup{}
go m.Find(args.filenames, args.recursive)
wg.Add(1)
go func() {
for e := range m.Errors() {
fail(e)
}
wg.Done()
}()
rc := make(chan fileResult, maxOpenFiles)
c := newFileChecker(
args.timeout,
args.documentRoot,
args.excludedPattern,
newSemaphore(args.concurrency))
go c.CheckMany(m.Filenames(), rc)
ok := true
for r := range rc {
if !r.Ok() {
ok = false
printToStderr(r.String(args.verbose))
} else if args.verbose {
printToStderr(r.String(true))
}
}
wg.Wait()
if !ok {
os.Exit(1)
}
}
func printToStderr(xs ...interface{}) {
if _, err := fmt.Fprintln(os.Stderr, xs...); err != nil {
panic(err)
}
}
func fail(err error) {
printToStderr(color.RedString(capitalizeFirst(err.Error())))
os.Exit(1)
}