-
Notifications
You must be signed in to change notification settings - Fork 5
/
project.go
60 lines (53 loc) · 1.52 KB
/
project.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
package tableprinters
import (
"fmt"
"strconv"
"strings"
"github.com/metal-stack/metal-go/api/models"
)
func (t *TablePrinter) ProjectTable(data []*models.V1ProjectResponse, wide bool) ([]string, [][]string, error) {
var (
rows [][]string
)
header := []string{"UID", "Tenant", "Name", "Description", "Labels", "Annotations"}
if wide {
header = []string{"UID", "Tenant", "Name", "Description", "Quotas Clusters/Machines/IPs", "Labels", "Annotations"}
}
for _, pr := range data {
quotas := "∞/∞/∞"
if pr.Quotas != nil {
clusterQuota := "∞"
machineQuota := "∞"
ipQuota := "∞"
qs := pr.Quotas
if qs.Cluster != nil {
if qs.Cluster.Quota != 0 {
clusterQuota = strconv.FormatInt(int64(qs.Cluster.Quota), 10)
}
}
if qs.Machine != nil {
if qs.Machine.Quota != 0 {
machineQuota = strconv.FormatInt(int64(qs.Machine.Quota), 10)
}
}
if qs.IP != nil {
if qs.IP.Quota != 0 {
ipQuota = strconv.FormatInt(int64(qs.IP.Quota), 10)
}
}
quotas = fmt.Sprintf("%s/%s/%s", clusterQuota, machineQuota, ipQuota)
}
labels := strings.Join(pr.Meta.Labels, "\n")
as := []string{}
for k, v := range pr.Meta.Annotations {
as = append(as, k+"="+v)
}
annotations := strings.Join(as, "\n")
if wide {
rows = append(rows, []string{pr.Meta.ID, pr.TenantID, pr.Name, pr.Description, quotas, labels, annotations})
} else {
rows = append(rows, []string{pr.Meta.ID, pr.TenantID, pr.Name, pr.Description, labels, annotations})
}
}
return header, rows, nil
}