-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtable.go
109 lines (83 loc) · 3.07 KB
/
table.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
// SPDX-License-Identifier: Apache-2.0
package repo
import (
"strings"
"github.com/go-vela/cli/internal/output"
"github.com/go-vela/types/library"
"github.com/gosuri/uitable"
"github.com/sirupsen/logrus"
)
// table is a helper function to output the
// provided repos in a table format with
// a specific set of fields displayed.
func table(repos *[]library.Repo) error {
logrus.Debug("creating table for list of repos")
// create a new table
//
// https://pkg.go.dev/github.com/gosuri/uitable?tab=doc#New
table := uitable.New()
// set column width for table to 50
//
// https://pkg.go.dev/github.com/gosuri/uitable?tab=doc#Table
table.MaxColWidth = 50
// ensure the table is always wrapped
//
// https://pkg.go.dev/github.com/gosuri/uitable?tab=doc#Table
table.Wrap = true
logrus.Trace("adding headers to repo table")
// set of repository fields we display in a table
//
// https://pkg.go.dev/github.com/gosuri/uitable?tab=doc#Table.AddRow
table.AddRow("ORG/REPO", "ACTIVE", "EVENTS", "VISIBILITY", "BRANCH")
// iterate through all repos in the list
for _, r := range *repos {
logrus.Tracef("adding repo %s to repo table", r.GetFullName())
//nolint:gosec // ignore memory aliasing
e := strings.Join(r.AllowEvents.List(), ",")
// add a row to the table with the specified values
//
// https://pkg.go.dev/github.com/gosuri/uitable?tab=doc#Table.AddRow
table.AddRow(r.GetFullName(), r.GetActive(), e, r.GetVisibility(), r.GetBranch())
}
// output the table in stdout format
//
// https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#Stdout
return output.Stdout(table)
}
// wideTable is a helper function to output the
// provided repos in a wide table format with
// a specific set of fields displayed.
func wideTable(repos *[]library.Repo) error {
logrus.Debug("creating wide table for list of repos")
// create new wide table
//
// https://pkg.go.dev/github.com/gosuri/uitable?tab=doc#New
table := uitable.New()
// set column width for wide table to 200
//
// https://pkg.go.dev/github.com/gosuri/uitable?tab=doc#Table
table.MaxColWidth = 200
// ensure the wide table is always wrapped
//
// https://pkg.go.dev/github.com/gosuri/uitable?tab=doc#Table
table.Wrap = true
logrus.Trace("adding headers to wide repo table")
// set of repository fields we display in a wide table
//
// https://pkg.go.dev/github.com/gosuri/uitable?tab=doc#Table.AddRow
table.AddRow("ORG/REPO", "ACTIVE", "EVENTS", "VISIBILITY", "BRANCH", "REMOTE")
// iterate through all repos in the list
for _, r := range *repos {
logrus.Tracef("adding repo %s to wide repo table", r.GetFullName())
//nolint:gosec // ignore memory aliasing
e := strings.Join(r.AllowEvents.List(), ",")
// add a row to the table with the specified values
//
// https://pkg.go.dev/github.com/gosuri/uitable?tab=doc#Table.AddRow
table.AddRow(r.GetFullName(), r.GetActive(), e, r.GetVisibility(), r.GetBranch(), r.GetLink())
}
// output the wide table in stdout format
//
// https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#Stdout
return output.Stdout(table)
}