-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
63 lines (57 loc) · 1.56 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
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
)
func main() {
modulePath := flag.String("path", "", "path to the module root (with go.mod file)")
reportFormat := flag.String("format", "log", "reporting type (github | log)")
flag.Parse()
var reporting Reporting
if *reportFormat == "github" {
reporting = GitHubReporting{}
} else if *reportFormat == "log" {
reporting = LogReporting{}
} else {
fmt.Printf("invalid -format value: %v\n", *reportFormat)
flag.Usage()
os.Exit(1)
}
var analysisPath string
var err error
if *modulePath == "" {
analysisPath, err = os.Getwd()
if err != nil {
fmt.Printf("unable to get working directory: %v\n", err)
flag.Usage()
os.Exit(1)
}
} else {
analysisPath, err = filepath.Abs(*modulePath)
if err != nil {
fmt.Printf("unable to expand path '%v' to absolute: %v\n", *modulePath, err)
flag.Usage()
os.Exit(1)
}
}
log.Printf("module path: %v", analysisPath)
assemblyLines, err := AnalyzeModuleAssembly(analysisPath)
if len(assemblyLines) == 0 && err != nil {
panic(fmt.Errorf("failed to analyze module assembly: %w", err))
}
if err != nil {
log.Printf("module analysis finished with non-critical error: %v", err)
}
project, err := LoadPackage(analysisPath)
if err != nil {
panic(fmt.Errorf("unable to load project '%v': %w", analysisPath, err))
}
funcRegistry := CreateFuncRegistry(project)
err = AnalyzeModuleAst(analysisPath, project, assemblyLines, funcRegistry, Govanish, reporting)
if err != nil {
panic(fmt.Errorf("failed to analyze module AST: %w", err))
}
}