-
Notifications
You must be signed in to change notification settings - Fork 5
/
filesystemlayout.go
51 lines (42 loc) · 1.28 KB
/
filesystemlayout.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 (
"bytes"
"fmt"
"sort"
"strings"
"text/tabwriter"
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-lib/pkg/pointer"
"github.com/olekukonko/tablewriter"
)
func (t *TablePrinter) FSLTable(data []*models.V1FilesystemLayoutResponse, wide bool) ([]string, [][]string, error) {
var (
header = []string{"ID", "Description", "Filesystems", "Sizes", "Images"}
rows [][]string
)
for _, fsl := range data {
imageConstraints := []string{}
for os, v := range fsl.Constraints.Images {
imageConstraints = append(imageConstraints, os+" "+v)
}
fsls := fsl.Filesystems
sort.Slice(fsls, func(i, j int) bool { return depth(fsls[i].Path) < depth(fsls[j].Path) })
fss := bytes.NewBufferString("")
w := tabwriter.NewWriter(fss, 0, 0, 0, ' ', 0)
for i, fs := range fsls {
fmt.Fprintf(w, "%s\t \t%s", fs.Path, *fs.Device)
if i != len(fsls)-1 {
fmt.Fprintln(w)
}
}
err := w.Flush()
if err != nil {
return nil, nil, err
}
rows = append(rows, []string{pointer.SafeDeref(fsl.ID), fsl.Description, fss.String(), strings.Join(fsl.Constraints.Sizes, "\n"), strings.Join(imageConstraints, "\n")})
}
t.t.MutateTable(func(table *tablewriter.Table) {
table.SetAutoWrapText(false)
})
return header, rows, nil
}