@@ -28,6 +28,7 @@ import (
28
28
"github.com/fatih/color"
29
29
"github.com/gobuffalo/flect"
30
30
"github.com/olekukonko/tablewriter"
31
+ "github.com/olekukonko/tablewriter/tw"
31
32
corev1 "k8s.io/api/core/v1"
32
33
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
33
34
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -65,11 +66,20 @@ var (
65
66
// Note: this function is exposed only for usage in clusterctl and Cluster API E2E tests.
66
67
func PrintObjectTree (tree * tree.ObjectTree , w io.Writer ) {
67
68
// Creates the output table
68
- tbl := tablewriter .NewWriter (w )
69
- tbl .SetHeader ([]string {"NAME" , "REPLICAS" , "AVAILABLE" , "READY" , "UP TO DATE" , "STATUS" , "REASON" , "SINCE" , "MESSAGE" })
69
+ cfg := getTableTreeConfig ()
70
+ tbl := tablewriter .NewTable (os .Stdin , tablewriter .WithConfig (cfg ), tablewriter .WithRendition (tw.Rendition { // Apply custom rendition
71
+ Settings : tw.Settings {
72
+ Separators : tw .SeparatorsNone , Lines : tw .LinesNone ,
73
+ },
74
+ Borders : tw .BorderNone ,
75
+ }),)
76
+
77
+ // tbl.SetCenterSeparator("") - rendition - https://github.com/olekukonko/tablewriter/blob/e520aed3bd36fcbc5935d6c4f778c38627788d1d/tw/symbols.go#L885
78
+ // tbl.SetRowSeparator("") - rendition - https://github.com/olekukonko/tablewriter/blob/e520aed3bd36fcbc5935d6c4f778c38627788d1d/tw/symbols.go#L885
79
+
80
+ // tbl := tablewriter.NewWriter(w)
81
+ tbl .Header ([]string {"NAME" , "REPLICAS" , "AVAILABLE" , "READY" , "UP TO DATE" , "STATUS" , "REASON" , "SINCE" , "MESSAGE" })
70
82
71
- formatTableTree (tbl )
72
- // Add row for the root object, the cluster, and recursively for all the nodes representing the cluster status.
73
83
addObjectRow ("" , tbl , tree , tree .GetRoot ())
74
84
75
85
// Prints the output table
@@ -80,10 +90,21 @@ func PrintObjectTree(tree *tree.ObjectTree, w io.Writer) {
80
90
// Note: this function is exposed only for usage in clusterctl and Cluster API E2E tests.
81
91
func PrintObjectTreeV1Beta1 (tree * tree.ObjectTree ) {
82
92
// Creates the output table
83
- tbl := tablewriter .NewWriter (os .Stdout )
84
- tbl .SetHeader ([]string {"NAME" , "READY" , "SEVERITY" , "REASON" , "SINCE" , "MESSAGE" })
93
+ // tbl := tablewriter.NewWriter(os.Stdout)
94
+ cfg := getTableTreeConfig ()
95
+ tbl := tablewriter .NewTable (os .Stdin , tablewriter .WithConfig (cfg ), tablewriter .WithRendition (tw.Rendition { // Apply custom rendition
96
+ Settings : tw.Settings {
97
+ Lines : tw.Lines {ShowHeaderLine : tw .Off },
98
+ },
99
+ Borders : tw.Border {Top : tw .Off , Bottom : tw .Off , Left : tw .Off , Right : tw .Off },
100
+ }),)
101
+ tbl .Header ([]string {"NAME" , "READY" , "SEVERITY" , "REASON" , "SINCE" , "MESSAGE" })
102
+
103
+ // tbl.SetRowSeparator("") // different - rendition - https://github.com/olekukonko/tablewriter/blob/e520aed3bd36fcbc5935d6c4f778c38627788d1d/tw/symbols.go#L885
104
+
105
+ // tbl.SetBorder(false) // different - rendition
85
106
86
- formatTableTreeV1Beta1 (tbl )
107
+ // formatTableTreeV1Beta1(tbl)
87
108
// Add row for the root object, the cluster, and recursively for all the nodes representing the cluster status.
88
109
addObjectRowV1Beta1 ("" , tbl , tree , tree .GetRoot ())
89
110
@@ -92,34 +113,37 @@ func PrintObjectTreeV1Beta1(tree *tree.ObjectTree) {
92
113
}
93
114
94
115
// formats the table with required attributes.
95
- func formatTableTree (tbl * tablewriter.Table ) {
96
- tbl .SetAutoWrapText (false )
97
- tbl .SetHeaderAlignment (tablewriter .ALIGN_LEFT )
98
- tbl .SetAlignment (tablewriter .ALIGN_LEFT )
99
-
100
- tbl .SetCenterSeparator ("" )
101
- tbl .SetRowSeparator ("" )
102
-
103
- tbl .SetHeaderLine (false )
104
- tbl .SetTablePadding (" " )
105
- tbl .SetNoWhiteSpace (true )
116
+ func getTableTreeConfig () (tablewriter.Config ) {
117
+ cfg := tablewriter.Config {
118
+ Row : tw.CellConfig {
119
+ Formatting : tw.CellFormatting {AutoWrap : tw .WrapNone },
120
+ Alignment : tw.CellAlignment {Global : tw .AlignLeft },
121
+ Padding : tw.CellPadding {Global : tw.Padding {Left : " " , Right : " " }},
122
+ },
123
+ Header : tw.CellConfig {
124
+ Alignment : tw.CellAlignment {Global : tw .AlignLeft },
125
+ },
126
+ Behavior : tw.Behavior {TrimSpace : tw .On },
127
+ }
128
+
129
+ return cfg
106
130
}
107
131
108
- // formats the table with required attributes.
109
- func formatTableTreeV1Beta1 (tbl * tablewriter.Table ) {
110
- tbl .SetAutoWrapText (false )
111
- tbl .SetHeaderAlignment (tablewriter .ALIGN_LEFT )
112
- tbl .SetAlignment (tablewriter .ALIGN_LEFT )
113
-
114
- tbl .SetCenterSeparator ("" )
115
- tbl .SetColumnSeparator ("" )
116
- tbl .SetRowSeparator ("" )
117
-
118
- tbl .SetHeaderLine (false )
119
- tbl .SetBorder (false )
120
- tbl .SetTablePadding (" " )
121
- tbl .SetNoWhiteSpace (true )
122
- }
132
+ // // formats the table with required attributes.
133
+ // func formatTableTreeV1Beta1(tbl *tablewriter.Table) {
134
+ // // tbl.SetAutoWrapText(false)
135
+ // // tbl.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
136
+ // // tbl.SetAlignment(tablewriter.ALIGN_LEFT)
137
+
138
+ // // tbl.SetCenterSeparator("")
139
+ // // tbl.SetColumnSeparator("")
140
+ // // tbl.SetRowSeparator("") // different - rendition
141
+
142
+ // // tbl.SetHeaderLine(false)
143
+ // // tbl.SetBorder(false) // different - rendition
144
+ // // tbl.SetTablePadding(" ")
145
+ // // tbl.SetNoWhiteSpace(true)
146
+ // }
123
147
124
148
// addObjectRow add a row for a given object, and recursively for all the object's children.
125
149
// NOTE: each row name gets a prefix, that generates a tree view like representation.
0 commit comments