-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
131 lines (107 loc) · 3.12 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"runtime"
"runtime/pprof"
"strings"
"github.com/sharovik/wt/configuration"
"github.com/sharovik/wt/services/printout"
"github.com/sharovik/wt/analysis"
"github.com/sharovik/wt/services"
"github.com/sharovik/wt/services/cli"
)
var (
vcs services.VcsInterface
cliService = cli.Service{}
)
func main() {
cliService.ParseArgs()
if cliService.CPUProfile != "" {
f, err := os.Create(cliService.CPUProfile)
if err != nil {
log.Fatal("could not create CPU profile: ", err)
}
defer f.Close() // error handling omitted for example
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatal("could not start CPU profile: ", err)
}
defer pprof.StopCPUProfile()
}
analysis.MaxDeepLevel = cliService.MaxAnalysisDepth
loadVcs(cliService.VcsType)
analysis.InitAnalysisService(cliService.Ext)
absolutePath, err := filepath.Abs(cliService.Path)
if err != nil {
return
}
paths, err := services.GetIgnoredFilePaths(cliService.PathToIgnoreFile, absolutePath)
if err != nil {
log.Fatal(err)
}
if cliService.IgnoreFromAnalysis != "" {
for _, path := range strings.Split(cliService.IgnoreFromAnalysis, ",") {
paths = append(paths, fmt.Sprintf("%s/%s", absolutePath, path))
}
}
index, pathIndex, importsIndex, err := services.AnalyseTheCode(absolutePath, cliService.Ext, paths)
if err != nil {
log.Fatal(err)
}
analysis.AnalysedEntrypointsIndex = index
analysis.AnalysedPathsIndex = pathIndex
analysis.AnalysedImportsIndex = importsIndex
diff, err := vcs.Diff(absolutePath, cliService.WorkingBranch, cliService.DestinationBranch)
if err != nil {
log.Fatal(err)
}
analysisResult := services.FindFeaturesInIndex(diff, absolutePath)
displayObj, err := printout.FromType(cliService.DisplayTemplate)
if err != nil {
log.Fatal(err)
}
displayObj.SetToBeChecked(analysisResult.ToBeChecked)
displayObj.SetTotalFeaturesTouched(analysisResult.TotalFeaturesTouched)
displayObj.SetAbsolutePath(absolutePath)
displayObj.SetConfig(configuration.C)
displayObj.SetProjectsToCheck(analysisResult.ProjectsToCheck)
if cliService.WithToBeChecked {
displayObj.WithToBeCheckedDetails()
}
if len(analysisResult.TotalFeaturesTouched) == 0 {
fmt.Println(displayObj.Text())
if cliService.MemProfile != "" {
f, err := os.Create(cliService.MemProfile)
if err != nil {
log.Fatal("could not create memory profile: ", err)
}
defer f.Close() // error handling omitted for example
runtime.GC() // get up-to-date statistics
if err := pprof.WriteHeapProfile(f); err != nil {
log.Fatal("could not write memory profile: ", err)
}
}
return
}
fmt.Println(displayObj.Text())
if cliService.MemProfile != "" {
f, err := os.Create(cliService.MemProfile)
if err != nil {
log.Fatal("could not create memory profile: ", err)
}
defer f.Close() // error handling omitted for example
runtime.GC() // get up-to-date statistics
if err := pprof.WriteHeapProfile(f); err != nil {
log.Fatal("could not write memory profile: ", err)
}
}
}
func loadVcs(vcsType string) {
switch vcsType {
case "git":
vcs = services.Git{}
break
}
}