-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprint.go
81 lines (71 loc) · 1.54 KB
/
print.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
package main
import (
"fmt"
"os"
"github.com/fatih/color"
"github.com/olekukonko/tablewriter"
"k8s.io/kubernetes/pkg/api"
)
func printTagList(tagList []string) {
for i, tag := range tagList {
fmt.Print(i + 1)
fmt.Print(" ")
fmt.Print(tag)
if i == 0 {
color.Green(" [NEW]")
} else {
fmt.Println()
}
}
}
func printPodsTable(pods []api.Pod) {
color.Red("=== Pod ===")
data := [][]string{}
for _, pod := range pods {
data = append(data, []string{
pod.Name,
pod.Spec.Containers[0].Image,
pod.Namespace,
pod.CreationTimestamp.String(),
})
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{
"Name",
"Image",
"Namespace",
"Created at",
})
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
table.SetCenterSeparator("|")
table.AppendBulk(data)
table.Render()
fmt.Println()
}
func printServicesTable(services []api.Service) {
color.Blue("=== Service ===")
data := [][]string{}
for _, service := range services {
data = append(data, []string{
service.Name,
service.Namespace,
service.Spec.Selector["color"],
service.CreationTimestamp.String(),
})
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{
"Name",
"Namespace",
"Color",
"Created at",
})
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
table.SetCenterSeparator("|")
table.AppendBulk(data)
table.Render()
fmt.Println()
}
func printReplace(old, new string) {
fmt.Println("Replace: " + old + " => " + new)
}