@@ -28,6 +28,7 @@ import (
2828	"github.com/fatih/color" 
2929	"github.com/gobuffalo/flect" 
3030	"github.com/olekukonko/tablewriter" 
31+ 	"github.com/olekukonko/tablewriter/tw" 
3132	corev1 "k8s.io/api/core/v1" 
3233	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 
3334	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 
@@ -64,12 +65,19 @@ var (
6465// PrintObjectTree prints the cluster status to stdout. 
6566// Note: this function is exposed only for usage in clusterctl and Cluster API E2E tests. 
6667func  PrintObjectTree (tree  * tree.ObjectTree , w  io.Writer ) {
68+ 
69+ 	cfg  :=  getObjectTreeConfig ()
6770	// Creates the output table 
68- 	tbl  :=  tablewriter .NewWriter (w )
69- 	tbl .SetHeader ([]string {"NAME" , "REPLICAS" , "AVAILABLE" , "READY" , "UP TO DATE" , "STATUS" , "REASON" , "SINCE" , "MESSAGE" })
71+ 	tbl  :=  tablewriter .NewTable (os .Stdin , tablewriter .WithConfig (cfg ), tablewriter .WithRendition (tw.Rendition {
72+ 		Settings : tw.Settings {
73+ 			Separators : tw .SeparatorsNone , Lines : tw .LinesNone ,
74+ 		},
75+ 		Borders : tw .BorderNone ,
76+ 	}))
77+ 
78+ 	// tbl := tablewriter.NewWriter(w) 
79+ 	tbl .Header ([]string {"NAME" , "REPLICAS" , "AVAILABLE" , "READY" , "UP TO DATE" , "STATUS" , "REASON" , "SINCE" , "MESSAGE" })
7080
71- 	formatTableTree (tbl )
72- 	// Add row for the root object, the cluster, and recursively for all the nodes representing the cluster status. 
7381	addObjectRow ("" , tbl , tree , tree .GetRoot ())
7482
7583	// Prints the output table 
@@ -79,48 +87,56 @@ func PrintObjectTree(tree *tree.ObjectTree, w io.Writer) {
7987// PrintObjectTreeV1Beta1 prints the cluster status to stdout. 
8088// Note: this function is exposed only for usage in clusterctl and Cluster API E2E tests. 
8189func  PrintObjectTreeV1Beta1 (tree  * tree.ObjectTree ) {
90+ 	cfg  :=  getObjectTreeConfigV1Beta1 ()
91+ 
8292	// Creates the output table 
83- 	tbl  :=  tablewriter .NewWriter (os .Stdout )
84- 	tbl .SetHeader ([]string {"NAME" , "READY" , "SEVERITY" , "REASON" , "SINCE" , "MESSAGE" })
93+ 	tbl  :=  tablewriter .NewTable (os .Stdin , tablewriter .WithConfig (cfg ), tablewriter .WithRendition (tw.Rendition {
94+ 		Settings : tw.Settings {
95+ 			Separators : tw .SeparatorsNone , Lines : tw .LinesNone ,
96+ 		},
97+ 		Borders : tw .BorderNone ,
98+ 	}))
99+ 	tbl .Header ([]string {"NAME" , "READY" , "SEVERITY" , "REASON" , "SINCE" , "MESSAGE" })
85100
86- 	formatTableTreeV1Beta1 (tbl )
87101	// Add row for the root object, the cluster, and recursively for all the nodes representing the cluster status. 
88102	addObjectRowV1Beta1 ("" , tbl , tree , tree .GetRoot ())
89103
90104	// Prints the output table 
91105	tbl .Render ()
92106}
93107
94- // 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 )
108+ // Creates custom configuration for the table for the object tree. 
109+ func  getObjectTreeConfig () tablewriter.Config  {
110+ 	cfg  :=  tablewriter.Config {
111+ 		Row : tw.CellConfig {
112+ 			Formatting : tw.CellFormatting {AutoWrap : tw .WrapNone },
113+ 			Alignment :  tw.CellAlignment {Global : tw .AlignLeft },
114+ 			Padding :    tw.CellPadding {Global : tw.Padding {Left : "" , Right : "  " }},
115+ 		},
116+ 		Header : tw.CellConfig {
117+ 			Alignment : tw.CellAlignment {Global : tw .AlignLeft },
118+ 		},
119+ 		Behavior : tw.Behavior {TrimSpace : tw .Off },
120+ 	}
121+ 
122+ 	return  cfg 
106123}
107124
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 ("" )
125+ func  getObjectTreeConfigV1Beta1 () tablewriter.Config  {
126+ 	cfg  :=  tablewriter.Config {
127+ 		Row : tw.CellConfig {
128+ 			Formatting : tw.CellFormatting {AutoWrap : tw .WrapNone },
129+ 			Alignment :  tw.CellAlignment {Global : tw .AlignLeft },
130+ 			Padding :    tw.CellPadding {Global : tw.Padding {Left : "" , Right : " " }},
131+ 		},
132+ 		Header : tw.CellConfig {
133+ 			Alignment : tw.CellAlignment {Global : tw .AlignLeft },
134+ 		},
135+ 		Behavior : tw.Behavior {TrimSpace : tw .Off },
136+ 	}
117137
118- 	tbl .SetHeaderLine (false )
119- 	tbl .SetBorder (false )
120- 	tbl .SetTablePadding ("  " )
121- 	tbl .SetNoWhiteSpace (true )
138+ 	return  cfg 
122139}
123- 
124140// addObjectRow add a row for a given object, and recursively for all the object's children. 
125141// NOTE: each row name gets a prefix, that generates a tree view like representation. 
126142func  addObjectRow (prefix  string , tbl  * tablewriter.Table , objectTree  * tree.ObjectTree , obj  ctrlclient.Object ) {
0 commit comments