Skip to content

Commit 75f528e

Browse files
committed
fix build errors after tablewriter bump to v1.1.4
Migrate from the removed v0.0.5 setter API (SetHeader, SetBorder, SetAlignment, etc.) to the new v1.1.4 configuration-driven API using Options, Configure, WithRendition, and WithHeader.
1 parent a47079f commit 75f528e

File tree

14 files changed

+136
-116
lines changed

14 files changed

+136
-116
lines changed

cmd/audit/lint.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"unicode"
1010

1111
"github.com/olekukonko/tablewriter"
12+
"github.com/olekukonko/tablewriter/tw"
1213
"github.com/spf13/cobra"
1314
"github.com/spf13/pflag"
1415
"github.com/superfly/flyctl/internal/command/root"
@@ -22,21 +23,22 @@ func newLintCmd() *cobra.Command {
2223
root := root.New()
2324
run := NewCheckRun(root)
2425

25-
table := tablewriter.NewWriter(os.Stdout)
26-
table.SetBorder(false)
27-
table.SetAutoWrapText(false)
28-
table.SetHeader([]string{"Path", "Check", "Failure Reason"})
26+
table := tablewriter.NewTable(os.Stdout,
27+
tablewriter.WithHeader([]string{"Path", "Check", "Failure Reason"}),
28+
tablewriter.WithRendition(tw.Rendition{
29+
Borders: tw.Border{Left: tw.Off, Right: tw.Off, Top: tw.Off, Bottom: tw.Off},
30+
}),
31+
)
32+
table.Configure(func(cfg *tablewriter.Config) {
33+
cfg.Row.Formatting.AutoWrap = tw.WrapNone
34+
})
2935

3036
errors := run.Run()
3137
for _, err := range errors {
32-
table.Append([]string{
33-
err.command,
34-
err.check,
35-
err.Error(),
36-
})
38+
table.Append(err.command, err.check, err.Error()) //nolint:errcheck
3739
}
3840

39-
table.Render()
41+
table.Render() //nolint:errcheck
4042

4143
fmt.Println()
4244
fmt.Printf("%d checks failed\n", len(errors))

cmd/audit/output.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88

99
"github.com/olekukonko/tablewriter"
10+
"github.com/olekukonko/tablewriter/tw"
1011
)
1112

1213
func newOutput(w io.Writer, format string) output {
@@ -25,23 +26,38 @@ type output interface {
2526
}
2627

2728
func NewTableOutput(w io.Writer) *tableOutput {
28-
t := tablewriter.NewWriter(w)
29-
t.SetBorder(false)
30-
t.SetAutoWrapText(false)
29+
t := tablewriter.NewTable(w,
30+
tablewriter.WithRendition(tw.Rendition{
31+
Borders: tw.Border{Left: tw.Off, Right: tw.Off, Top: tw.Off, Bottom: tw.Off},
32+
}),
33+
)
34+
t.Configure(func(cfg *tablewriter.Config) {
35+
cfg.Row.Formatting.AutoWrap = tw.WrapNone
36+
})
3137

3238
return &tableOutput{
33-
Table: t,
39+
table: t,
3440
}
3541
}
3642

3743
type tableOutput struct {
38-
*tablewriter.Table
44+
table *tablewriter.Table
3945
}
4046

41-
func (t *tableOutput) Flush() error {
42-
t.Render()
47+
func (t *tableOutput) SetHeader(header []string) {
48+
t.table.Options(tablewriter.WithHeader(header))
49+
}
50+
51+
func (t *tableOutput) Append(row []string) {
52+
args := make([]interface{}, len(row))
53+
for i, v := range row {
54+
args[i] = v
55+
}
56+
t.table.Append(args...) //nolint:errcheck
57+
}
4358

44-
return nil
59+
func (t *tableOutput) Flush() error {
60+
return t.table.Render()
4561
}
4662

4763
func NewCSVOutput(w io.Writer) *csvOutput {

helpers/tablehelper.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,22 @@ import (
44
"io"
55

66
tablewriter "github.com/olekukonko/tablewriter"
7+
"github.com/olekukonko/tablewriter/tw"
78
)
89

910
func MakeSimpleTable(out io.Writer, headings []string) (table *tablewriter.Table) {
10-
newtable := tablewriter.NewWriter(out)
11-
// Future code to turn headers bold
12-
// headercolors := []tablewriter.Colors{}
13-
// for range headings {
14-
// headercolors = append(headercolors, tablewriter.Colors{tablewriter.Bold})
15-
// }
16-
newtable.SetHeader(headings)
17-
newtable.SetHeaderLine(true)
18-
newtable.SetBorder(false)
19-
newtable.SetAutoFormatHeaders(true)
20-
newtable.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
21-
newtable.SetAlignment(tablewriter.ALIGN_LEFT)
22-
newtable.SetTablePadding(" ")
23-
newtable.SetCenterSeparator("*")
24-
newtable.SetRowSeparator("-")
25-
newtable.SetAutoWrapText(false)
11+
newtable := tablewriter.NewTable(out,
12+
tablewriter.WithHeader(headings),
13+
tablewriter.WithHeaderAlignment(tw.AlignLeft),
14+
tablewriter.WithRowAlignment(tw.AlignLeft),
15+
tablewriter.WithRendition(tw.Rendition{
16+
Borders: tw.Border{Left: tw.Off, Right: tw.Off, Top: tw.Off, Bottom: tw.Off},
17+
}),
18+
)
19+
newtable.Configure(func(cfg *tablewriter.Config) {
20+
cfg.Header.Formatting.AutoFormat = tw.On
21+
cfg.Row.Formatting.AutoWrap = tw.WrapNone
22+
})
2623

2724
return newtable
2825
}

internal/command/checks/list.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ func runAppCheckList(ctx context.Context) error {
4545

4646
fmt.Fprintf(out, "Health Checks for %s\n", appName)
4747
table := helpers.MakeSimpleTable(out, []string{"Name", "Status", "Machine", "Last Updated", "Output"})
48-
table.SetRowLine(true)
4948
for _, machine := range machines {
5049
sort.Slice(machine.Checks, func(i, j int) bool {
5150
return machine.Checks[i].Name < machine.Checks[j].Name
@@ -55,10 +54,10 @@ func runAppCheckList(ctx context.Context) error {
5554
if nameFilter != "" && nameFilter != check.Name {
5655
continue
5756
}
58-
table.Append([]string{check.Name, string(check.Status), machine.ID, format.RelativeTime(*check.UpdatedAt), check.Output})
57+
table.Append(check.Name, string(check.Status), machine.ID, format.RelativeTime(*check.UpdatedAt), check.Output) //nolint:errcheck
5958
}
6059
}
61-
table.Render()
60+
table.Render() //nolint:errcheck
6261

6362
return nil
6463
}

internal/command/deploy/machines_deploymachinesapp.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,10 +1301,10 @@ func (md *machineDeployment) warnAboutIncorrectListenAddress(ctx context.Context
13011301
}
13021302
}
13031303
if len(addresses) > 0 {
1304-
table.Append([]string{proc.Command, strings.Join(addresses, ", ")})
1304+
table.Append(proc.Command, strings.Join(addresses, ", ")) //nolint:errcheck
13051305
}
13061306
}
1307-
table.Render()
1307+
table.Render() //nolint:errcheck
13081308
fmt.Fprintf(md.io.ErrOut, "\n")
13091309
}
13101310

internal/command/incidents/hosts/list.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ func runList(ctx context.Context) (err error) {
6161
if appHostIssuesCount > 0 {
6262
fmt.Fprintf(out, "Host Issues count: %d\n\n", appHostIssuesCount)
6363
table := helpers.MakeSimpleTable(out, []string{"Id", "Message", "Started At", "Last Updated"})
64-
table.SetRowLine(true)
6564
for _, appHostIssue := range appHostIssues {
66-
table.Append([]string{appHostIssue.InternalId, appHostIssue.Message, appHostIssue.CreatedAt.String(), appHostIssue.UpdatedAt.String()})
65+
table.Append(appHostIssue.InternalId, appHostIssue.Message, appHostIssue.CreatedAt.String(), appHostIssue.UpdatedAt.String()) //nolint:errcheck
6766
}
68-
table.Render()
67+
table.Render() //nolint:errcheck
6968
} else {
7069
fmt.Fprintf(out, "There are no active host issues\n")
7170
}

internal/command/incidents/incidents.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,14 @@ func runIncidentsList(ctx context.Context) error {
6666
if incidentCount > 0 {
6767
fmt.Fprintf(out, "Incidents count: %d\n\n", incidentCount)
6868
table := helpers.MakeSimpleTable(out, []string{"Id", "Name", "Status", "Components", "Started At", "Last Updated"})
69-
table.SetRowLine(true)
7069
for _, incident := range statuspageIncidents.Incidents {
7170
var components []string
7271
for _, component := range incident.Components {
7372
components = append(components, component.Name)
7473
}
75-
table.Append([]string{incident.ID, incident.Name, incident.Status, strings.Join(components, ", "), incident.StartedAt, incident.UpdatedAt})
74+
table.Append(incident.ID, incident.Name, incident.Status, strings.Join(components, ", "), incident.StartedAt, incident.UpdatedAt) //nolint:errcheck
7675
}
77-
table.Render()
76+
table.Render() //nolint:errcheck
7877
} else {
7978
fmt.Fprintf(out, "There are no active incidents\n")
8079
}

internal/command/orgs/show.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,14 @@ func runShow(ctx context.Context) (err error) {
7373

7474
fmt.Fprintln(&buf, colorize.Bold("Organization Members"))
7575

76-
membertable := tablewriter.NewWriter(&buf)
77-
membertable.SetHeader([]string{"Name", "Email", "Role"})
76+
membertable := tablewriter.NewTable(&buf,
77+
tablewriter.WithHeader([]string{"Name", "Email", "Role"}),
78+
)
7879

7980
for _, m := range org.Members.Edges {
80-
membertable.Append([]string{m.Node.Name, m.Node.Email, m.Role})
81+
membertable.Append(m.Node.Name, m.Node.Email, m.Role) //nolint:errcheck
8182
}
82-
membertable.Render()
83+
membertable.Render() //nolint:errcheck
8384

8485
buf.WriteTo(io.Out)
8586

internal/command/root/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"path/filepath"
99

1010
"github.com/kr/text"
11-
"github.com/olekukonko/tablewriter"
11+
"github.com/olekukonko/tablewriter/tw"
1212
"github.com/spf13/cobra"
1313

1414
"github.com/superfly/flyctl/flyctl"
@@ -232,7 +232,7 @@ func run(ctx context.Context) error {
232232
if err != nil {
233233
panic(err)
234234
}
235-
cmd.Printf(" %s %s\n", tablewriter.PadRight(c.CommandPath(), " ", 16), c.Short)
235+
cmd.Printf(" %s %s\n", tw.PadRight(c.CommandPath(), " ", 16), c.Short)
236236
}
237237

238238
cmd.Println()

internal/command/ssh/log.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,9 @@ func runLog(ctx context.Context) (err error) {
5454
return nil
5555
}
5656

57-
table := tablewriter.NewWriter(out)
58-
59-
table.SetHeader([]string{
60-
"Root",
61-
"Certificate",
62-
})
57+
table := tablewriter.NewTable(out,
58+
tablewriter.WithHeader([]string{"Root", "Certificate"}),
59+
)
6360

6461
for _, cert := range certs {
6562
root := "no"
@@ -72,7 +69,7 @@ func runLog(ctx context.Context) (err error) {
7269
for i, ch := range cert.Cert {
7370
buf.WriteRune(ch)
7471
if i%60 == 0 && i != 0 {
75-
table.Append([]string{root, buf.String()})
72+
table.Append(root, buf.String()) //nolint:errcheck
7673
if first {
7774
root = ""
7875
first = false
@@ -82,11 +79,11 @@ func runLog(ctx context.Context) (err error) {
8279
}
8380

8481
if buf.Len() != 0 {
85-
table.Append([]string{root, buf.String()})
82+
table.Append(root, buf.String()) //nolint:errcheck
8683
}
8784
}
8885

89-
table.Render()
86+
table.Render() //nolint:errcheck
9087

9188
return nil
9289
}

0 commit comments

Comments
 (0)