-
Notifications
You must be signed in to change notification settings - Fork 5
/
image.go
44 lines (36 loc) · 1.05 KB
/
image.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
package tableprinters
import (
"fmt"
"strings"
"time"
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-lib/pkg/pointer"
"github.com/spf13/viper"
)
func (t *TablePrinter) ImageTable(data []*models.V1ImageResponse, wide bool) ([]string, [][]string, error) {
var (
rows [][]string
header = []string{"ID", "Name", "Description", "Features", "Expiration", "Status", "UsedBy"}
showUsage = viper.GetBool("show-usage")
)
for _, image := range data {
id := pointer.SafeDeref(image.ID)
features := strings.Join(image.Features, ",")
name := image.Name
description := image.Description
status := image.Classification
expiration := ""
if image.ExpirationDate != nil {
expiration = humanizeDuration(time.Until(time.Time(*image.ExpirationDate)))
}
usedBy := fmt.Sprintf("%d", len(image.Usedby))
if wide {
usedBy = strings.Join(image.Usedby, "\n")
}
if !showUsage {
usedBy = ""
}
rows = append(rows, []string{id, name, description, features, expiration, status, usedBy})
}
return header, rows, nil
}