@@ -28,7 +28,9 @@ import (
28
28
"strings"
29
29
30
30
"github.com/google/go-github/v32/github"
31
+ "github.com/olekukonko/tablewriter"
31
32
"gopkg.in/yaml.v2"
33
+
32
34
"k8s.io/enhancements/pkg/kepval/keps"
33
35
)
34
36
@@ -173,7 +175,7 @@ func findLocalKEPs(repoPath string, sig string) ([]string, error) {
173
175
return keps , err
174
176
}
175
177
176
- func (c * Client ) findPRKEPs (sig string ) (* keps.Proposal , error ) {
178
+ func (c * Client ) findKEPPullRequests (sig string ) (* keps.Proposal , error ) {
177
179
gh := github .NewClient (nil )
178
180
pulls , _ , err := gh .PullRequests .List (context .Background (), "kubernetes" , "enhancements" , & github.PullRequestListOptions {})
179
181
if err != nil {
@@ -266,42 +268,39 @@ func (c *Client) writeKEP(kep *keps.Proposal, opts CommonArgs) error {
266
268
267
269
type PrintConfig interface {
268
270
Title () string
269
- Format () string
270
271
Value (* keps.Proposal ) string
271
272
}
272
273
273
274
type printConfig struct {
274
275
title string
275
- format string
276
276
valueFunc func (* keps.Proposal ) string
277
277
}
278
278
279
- func (p * printConfig ) Title () string { return p .title }
280
- func (p * printConfig ) Format () string { return p .format }
279
+ func (p * printConfig ) Title () string { return p .title }
281
280
func (p * printConfig ) Value (k * keps.Proposal ) string {
282
281
return p .valueFunc (k )
283
282
}
284
283
285
- var dfltConfig = map [string ]printConfig {
286
- "Authors" : {"Authors" , "%-30s" , func (k * keps.Proposal ) string { return strings .Join (k .Authors , ", " ) }},
287
- "LastUpdated" : {"Updated" , "%-10s" , func (k * keps.Proposal ) string { return k .LastUpdated }},
288
- "SIG" : {"SIG" , "%-12s" , func (k * keps.Proposal ) string {
284
+ var defaultConfig = map [string ]printConfig {
285
+ "Authors" : {"Authors" , func (k * keps.Proposal ) string { return strings .Join (k .Authors , ", " ) }},
286
+ "LastUpdated" : {"Updated" , func (k * keps.Proposal ) string { return k .LastUpdated }},
287
+ "SIG" : {"SIG" , func (k * keps.Proposal ) string {
289
288
if strings .HasPrefix (k .OwningSIG , "sig-" ) {
290
289
return k .OwningSIG [4 :]
291
290
} else {
292
291
return k .OwningSIG
293
292
}
294
293
}},
295
- "Stage" : {"Stage" , "%-6s" , func (k * keps.Proposal ) string { return k .Stage }},
296
- "Status" : {"Status" , "%-16s" , func (k * keps.Proposal ) string { return k .Status }},
297
- "Title" : {"Title" , "%-30s" , func (k * keps.Proposal ) string { return k .Title }},
294
+ "Stage" : {"Stage" , func (k * keps.Proposal ) string { return k .Stage }},
295
+ "Status" : {"Status" , func (k * keps.Proposal ) string { return k .Status }},
296
+ "Title" : {"Title" , func (k * keps.Proposal ) string { return k .Title }},
298
297
}
299
298
300
299
func DefaultPrintConfigs (names ... string ) []PrintConfig {
301
300
var configs []PrintConfig
302
301
for _ , n := range names {
303
302
// copy to allow it to be tweaked by the caller
304
- c := dfltConfig [n ]
303
+ c := defaultConfig [n ]
305
304
configs = append (configs , & c )
306
305
}
307
306
return configs
@@ -312,24 +311,21 @@ func (c *Client) PrintTable(configs []PrintConfig, proposals []*keps.Proposal) {
312
311
return
313
312
}
314
313
315
- fstr := configs [0 ].Format ()
316
- for _ , c := range configs [1 :] {
317
- fstr += " " + c .Format ()
318
- }
319
- fstr += "\n "
320
-
321
- fmt .Fprintf (c .Out , fstr , mapPrintConfigs (configs , func (p PrintConfig ) string { return p .Title () })... )
322
- fmt .Fprintf (c .Out , fstr , mapPrintConfigs (configs , func (p PrintConfig ) string { return strings .Repeat ("-" , len (p .Title ())) })... )
314
+ table := tablewriter .NewWriter (c .Out )
323
315
324
- for _ , k := range proposals {
325
- fmt .Fprintf (c .Out , fstr , mapPrintConfigs (configs , func (p PrintConfig ) string { return p .Value (k ) })... )
316
+ var headers []string
317
+ for _ , c := range configs {
318
+ headers = append (headers , c .Title ())
326
319
}
327
- }
320
+ table .SetHeader (headers )
321
+ table .SetAlignment (tablewriter .ALIGN_LEFT )
328
322
329
- func mapPrintConfigs (configs []PrintConfig , mapFunc func (p PrintConfig ) string ) []interface {} {
330
- var s []interface {}
331
- for _ , c := range configs {
332
- s = append (s , mapFunc (c ))
323
+ for _ , k := range proposals {
324
+ var s []string
325
+ for _ , c := range configs {
326
+ s = append (s , c .Value (k ))
327
+ }
328
+ table .Append (s )
333
329
}
334
- return s
330
+ table . Render ()
335
331
}
0 commit comments