-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
54 lines (50 loc) · 1.11 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
package main
import (
"github.com/alecthomas/kingpin/v2"
"github.com/hashicorp/go-multierror"
"github.com/orange-cloudfoundry/config-patcher/model"
"github.com/prometheus/common/version"
"gopkg.in/yaml.v2"
"log"
"os"
"path/filepath"
)
var (
patchFlag = kingpin.
Flag("patch", "Set in glob format where to find rules for patching config files").
Default("/var/vcap/jobs/*/config-patcher/*.yml").
String()
)
func main() {
kingpin.Version(version.Print("config-patcher"))
kingpin.HelpFlag.Short('h')
kingpin.Parse()
filesMatch, err := filepath.Glob(*patchFlag)
if err != nil {
log.Fatal(err)
}
patches := make([]model.Patch, 0)
for _, file := range filesMatch {
b, err := os.ReadFile(file)
if err != nil {
log.Fatal(err)
}
patchTmp := make([]model.Patch, 0)
err = yaml.Unmarshal(b, &patchTmp)
if err != nil {
log.Fatal(err)
}
patches = append(patches, patchTmp...)
}
var result error
for _, patch := range patches {
patcher := NewPatcher(patch)
err = patcher.Patch()
if err != nil {
result = multierror.Append(result, err)
}
}
if result != nil {
log.Fatal(result)
}
}