-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
62 lines (50 loc) · 954 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
package main
import (
"flag"
"fmt"
"os"
"sync"
)
const version = "0.1"
func main() {
configFile := flag.String("config", "config.yml", "")
showVersion := flag.Bool("v", false, "Shows the version information")
flag.Parse()
if *showVersion {
showVersionInfo()
os.Exit(0)
}
process(*configFile)
}
func showVersionInfo() {
fmt.Println("in-replace")
fmt.Println("Version:", version)
fmt.Println("Author: Daniel Czerwonk")
}
func process(configFile string) {
config, err := loadConfigFromFile(configFile)
if err != nil {
fmt.Println("failed loading config: ", err)
os.Exit(1)
}
if !processFiles(config) {
os.Exit(2)
}
}
func processFiles(c *Config) bool {
wg := sync.WaitGroup{}
res := true
for _, f := range c.Files {
wg.Add(1)
go func(f *File) {
defer wg.Done()
err := processFile(f)
if err != nil {
fmt.Printf("error (%s): %v", f.Path, err)
res = false
}
}(f)
}
wg.Wait()
return res
}