-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresult.go
97 lines (86 loc) · 2.02 KB
/
result.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
package main
import (
"fmt"
"io"
"strconv"
"time"
"github.com/Nivl/check-go-deps/modutil"
"github.com/olekukonko/tablewriter"
)
// Results contains all the modules that need to be reported
type Results struct {
Updated []*modutil.Module
Replaced []*modutil.Module
Old []*modutil.Module
}
// HasModules checks if the results contains any modules
func (r *Results) HasModules() bool {
return len(r.Updated) > 0 ||
len(r.Replaced) > 0 ||
len(r.Old) > 0
}
func (r *Results) print(w io.Writer) {
needSpacing := false
if len(r.Updated) > 0 {
needSpacing = true
table := tablewriter.NewWriter(w)
table.SetHeader([]string{"Module", "Current Version", "New Version", "Indirect"})
table.SetColumnAlignment([]int{
tablewriter.ALIGN_LEFT,
tablewriter.ALIGN_CENTER,
tablewriter.ALIGN_CENTER,
tablewriter.ALIGN_CENTER,
})
for _, m := range r.Updated {
table.Append([]string{
m.Path,
m.Version,
m.Update.Version,
strconv.FormatBool(m.Indirect),
})
}
table.Render()
}
if len(r.Replaced) > 0 {
if needSpacing {
fmt.Fprintln(w)
}
needSpacing = true
table := tablewriter.NewWriter(w)
table.SetHeader([]string{"Module", "Replaced By", "Indirect"})
table.SetColumnAlignment([]int{
tablewriter.ALIGN_LEFT,
tablewriter.ALIGN_LEFT,
tablewriter.ALIGN_CENTER,
})
for _, m := range r.Replaced {
table.Append([]string{
m.Path,
m.Replace.Path,
strconv.FormatBool(m.Indirect),
})
}
table.Render()
}
if len(r.Old) > 0 {
if needSpacing {
fmt.Fprintln(w)
}
table := tablewriter.NewWriter(w)
table.SetHeader([]string{"Module", "Last update", "Indirect"})
table.SetColumnAlignment([]int{
tablewriter.ALIGN_LEFT,
tablewriter.ALIGN_CENTER,
tablewriter.ALIGN_CENTER,
})
for _, m := range r.Old {
monthsPassed := time.Since(*m.Time) / (24 * time.Hour) / 30
table.Append([]string{
m.Path,
fmt.Sprintf("%d months ago (%s)", monthsPassed, m.Time.Format("2006/01/02")),
strconv.FormatBool(m.Indirect),
})
}
table.Render()
}
}