forked from ribice/glice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
changes.go
46 lines (40 loc) · 1.05 KB
/
changes.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
package glice
import "sort"
type Changes struct {
Additions Dependencies
Deletions Dependencies
}
func NewChanges() *Changes {
return &Changes{
Additions: make(Dependencies, 0),
Deletions: make(Dependencies, 0),
}
}
// HasChanges returns true if there are either old or new changes
func (c *Changes) HasChanges() bool {
return len(c.Additions) > 0 || len(c.Deletions) > 0
}
// LogPrint outputs all changes, old and new
func (c *Changes) LogPrint() {
LogPrintFunc(WarnLevel, func() {
showChanges(c.Additions, "Additions", "These imports were not found in glice.yaml but were found when scanning:")
showChanges(c.Deletions, "Deletions", "These imports were not found when scanning but were found in glice.yaml:")
})
}
func showChanges(list Dependencies, _type, descr string) {
if len(list) == 0 {
goto end
}
sort.Slice(list, func(i, j int) bool {
return list[i].Import < list[j].Import
})
Notef("\n%s", _type)
Notef("\n---------")
Notef("\n%s", descr)
Notef("\n")
for _, dep := range list {
Notef("\n - %s", dep.Import)
}
Notef("\n\n")
end:
}