-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
113 lines (87 loc) · 2.88 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
package main
import (
"flag"
"fmt"
"os"
"strings"
"telescope/telescope"
)
type IgnoredExpressions map[string]bool
func (i *IgnoredExpressions) String() string {
return fmt.Sprintln(i.ToSlice())
}
func (i *IgnoredExpressions) Set(value string) error {
(*i)[value] = true
return nil
}
func (i *IgnoredExpressions) ToSlice() []string {
var ignored []string
for dep := range *i {
ignored = append(ignored, dep)
}
return ignored
}
type CriticalExpressions map[string]telescope.OutdatedScope
func (c *CriticalExpressions) String() string {
var buffer string
criticalMap := c.ToScopeMap()
for _, scp := range telescope.OutdatedScopeSeries {
buffer += fmt.Sprintf("[ %s ]\n%s\n", scp, criticalMap[scp])
}
return buffer
}
func (c *CriticalExpressions) Set(value string) error {
desiredScopeStr, expression, found := strings.Cut(value, ":")
expressionMap := map[string]telescope.OutdatedScope(*c)
if !found {
desiredScopeStr, expression = telescope.MAJOR.String(), desiredScopeStr
}
desiredScope := telescope.OutdatedScopeStrToEnum(desiredScopeStr)
if registeredScope, ok := expressionMap[expression]; ok {
expressionMap[expression] = telescope.GetTopScope(
[]telescope.OutdatedScope{registeredScope, desiredScope},
)
} else {
expressionMap[expression] = desiredScope
}
return nil
}
func (c *CriticalExpressions) ToScopeMap() map[telescope.OutdatedScope][]string {
var criticalMap map[telescope.OutdatedScope][]string = map[telescope.OutdatedScope][]string{}
for dep, scp := range *c {
criticalMap[scp] = append(criticalMap[scp], dep)
}
return criticalMap
}
var (
filePath string
outdatedScope string
skipUnknown bool
strictSemVer bool
ignoredExpressions IgnoredExpressions = make(map[string]bool)
criticalExpressions CriticalExpressions = make(map[string]telescope.OutdatedScope)
)
func init() {
flag.StringVar(&filePath, "f", "go.mod", "dependencies file path")
flag.StringVar(&outdatedScope, "s", "major", "desired outdated scope")
flag.BoolVar(&skipUnknown, "skip-unknown", false, "skip dependencies with unknown versions")
flag.BoolVar(&strictSemVer, "strict-semver", false, "parse dependencies file with strict SemVer format")
flag.Var(&ignoredExpressions, "i", "ignore specific dependencies with regular expression")
flag.Var(&criticalExpressions, "c", "highlight critical dependencies with regular expression")
flag.Usage = usage
}
func usage() {
fmt.Fprintf(os.Stderr, "Usage: telescope [-f file_path] [-s outdated_scope] [-i ignored_dependency] [-c critical_dependency] [--skip-unknown] [--strict-semver]\n")
flag.PrintDefaults()
}
func main() {
flag.Parse()
atlas := telescope.NewAtlas(filePath, strictSemVer, ignoredExpressions.ToSlice(), criticalExpressions.ToScopeMap())
criticalFound := atlas.ReportOutdated(
telescope.OutdatedScopeStrToEnum(outdatedScope),
skipUnknown,
)
if criticalFound {
os.Exit(1)
}
}