@@ -84,8 +84,26 @@ func listPods(c *cli.Context) error {
84
84
log .Fatalf ("[ListPods] send request failed %v" , err )
85
85
}
86
86
87
- for _ , pod := range resp .GetPods () {
88
- log .Infof ("Name: %s, Desc: %s" , pod .GetName (), pod .GetDesc ())
87
+ if c .Bool ("pretty" ) {
88
+ t := table .NewWriter ()
89
+ t .SetOutputMirror (os .Stdout )
90
+ t .AppendHeader (table.Row {"Name" , "Description" })
91
+ nameRow := []string {}
92
+ descRow := []string {}
93
+ for _ , pod := range resp .GetPods () {
94
+ nameRow = append (nameRow , pod .Name )
95
+ descRow = append (descRow , pod .Desc )
96
+
97
+ }
98
+ rows := [][]string {nameRow , descRow }
99
+ t .AppendRows (toTableRows (rows ))
100
+ t .AppendSeparator ()
101
+ t .SetStyle (table .StyleLight )
102
+ t .Render ()
103
+ } else {
104
+ for _ , pod := range resp .GetPods () {
105
+ log .Infof ("Name: %s, Desc: %s" , pod .GetName (), pod .GetDesc ())
106
+ }
89
107
}
90
108
return nil
91
109
}
@@ -193,8 +211,25 @@ func listPodNodes(c *cli.Context) error {
193
211
return cli .Exit (err , - 1 )
194
212
}
195
213
196
- for _ , node := range resp .GetNodes () {
197
- log .Infof ("Name: %s, Endpoint: %s" , node .GetName (), node .GetEndpoint ())
214
+ if c .Bool ("pretty" ) {
215
+ t := table .NewWriter ()
216
+ t .SetOutputMirror (os .Stdout )
217
+ t .AppendHeader (table.Row {"Name" , "Endpoint" })
218
+ nameRow := []string {}
219
+ endpointRow := []string {}
220
+ for _ , node := range resp .Nodes {
221
+ nameRow = append (nameRow , node .Name )
222
+ endpointRow = append (endpointRow , node .Endpoint )
223
+ }
224
+ rows := [][]string {nameRow , endpointRow }
225
+ t .AppendRows (toTableRows (rows ))
226
+ t .AppendSeparator ()
227
+ t .SetStyle (table .StyleLight )
228
+ t .Render ()
229
+ } else {
230
+ for _ , node := range resp .GetNodes () {
231
+ log .Infof ("Name: %s, Endpoint: %s" , node .GetName (), node .GetEndpoint ())
232
+ }
198
233
}
199
234
return nil
200
235
}
@@ -215,8 +250,25 @@ func listPodNetworks(c *cli.Context) error {
215
250
return cli .Exit (err , - 1 )
216
251
}
217
252
218
- for _ , network := range resp .GetNetworks () {
219
- log .Infof ("Name: %s, Subnets: %s" , network .GetName (), strings .Join (network .GetSubnets (), "," ))
253
+ if c .Bool ("pretty" ) {
254
+ t := table .NewWriter ()
255
+ t .SetOutputMirror (os .Stdout )
256
+ t .AppendHeader (table.Row {"Name" , "Network" })
257
+ nameRow := []string {}
258
+ networkRow := []string {}
259
+ for _ , network := range resp .Networks {
260
+ nameRow = append (nameRow , network .Name )
261
+ networkRow = append (networkRow , strings .Join (network .GetSubnets (), "," ))
262
+ }
263
+ rows := [][]string {nameRow , networkRow }
264
+ t .AppendRows (toTableRows (rows ))
265
+ t .AppendSeparator ()
266
+ t .SetStyle (table .StyleLight )
267
+ t .Render ()
268
+ } else {
269
+ for _ , network := range resp .GetNetworks () {
270
+ log .Infof ("Name: %s, Subnets: %s" , network .GetName (), strings .Join (network .GetSubnets (), "," ))
271
+ }
220
272
}
221
273
return nil
222
274
}
0 commit comments