-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (63 loc) · 1.51 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
60
61
62
63
64
65
66
67
68
69
// zeno is a command line tool to analyse ansible playbook dependencies
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"path"
"strings"
"github.com/meomap/zeno/loader"
"github.com/meomap/zeno/search"
)
func main() {
var (
filesIn = flag.String("files", "", "names of changed files from command 'git diff $BEFORE $AFTER --name-only'")
debug = flag.Bool("debug", false, "enable for verbose logging")
pbsIn = flag.String("playbooks", "", "comma separated list of playbooks to examined")
)
flag.Parse()
// required args
if *pbsIn == "" {
flag.PrintDefaults()
os.Exit(1)
}
if *filesIn == "" {
return
}
if *debug == false {
log.SetOutput(ioutil.Discard)
}
diffFiles := strings.Split(*filesIn, "\n")
repoDir, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
lenDiffs := len(diffFiles)
// construct absolute path for input files
for i := 0; i < lenDiffs; i++ {
diffFiles[i] = path.Join(repoDir, diffFiles[i])
}
pbFiles := strings.Split(*pbsIn, ",")
lenPbs := len(pbFiles)
log.Printf("Match against [%d] files", lenDiffs)
log.Printf("Examine [%d] playbooks: %s\n", lenPbs, *pbsIn)
ds := new(loader.FileLoader)
var (
matched bool
out []string
)
for i := 0; i < lenPbs; i++ {
name := pbFiles[i]
if matched, err = search.MatchPlaybook(name, diffFiles, repoDir, ds); err != nil {
log.Fatal(err)
} else if matched {
out = append(out, name)
}
}
fmt.Println(strings.Join(out, ","))
}
func init() {
log.SetFlags(log.LstdFlags | log.Lmicroseconds | log.Lshortfile)
}