/
tenant.go
51 lines (43 loc) · 1.29 KB
/
tenant.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
package tableprinters
import (
"fmt"
"strconv"
"strings"
"github.com/dustin/go-humanize"
apiv1 "github.com/metal-stack-cloud/api/go/api/v1"
)
func (t *TablePrinter) TenantTable(data []*apiv1.Tenant, wide bool) ([]string, [][]string, error) {
var (
rows [][]string
)
header := []string{"ID", "Name", "Email", "Provider", "Registered", "Admitted", "Coupons"}
if wide {
header = []string{"ID", "Name", "Email", "Provider", "Registered", "Admitted", "Coupons"}
}
for _, tenant := range data {
id := tenant.Login
name := tenant.Name
email := tenant.Email
admitted := strconv.FormatBool(tenant.Admitted)
since := humanize.Time(tenant.CreatedAt.AsTime())
provider := tenant.OauthProvider.Enum().String()
coupons := "-"
couponsWide := coupons
if tenant.PaymentDetails != nil {
cs := []string{}
csw := []string{}
for _, c := range tenant.PaymentDetails.Coupons {
cs = append(cs, c.Name)
csw = append(csw, fmt.Sprintf("%s %s", c.Name, c.CreatedAt.AsTime()))
}
coupons = strings.Join(cs, "\n")
couponsWide = strings.Join(csw, "\n")
}
if wide {
rows = append(rows, []string{id, name, email, provider, since, admitted, couponsWide})
} else {
rows = append(rows, []string{id, name, email, provider, since, admitted, coupons})
}
}
return header, rows, nil
}