Skip to content

Commit 3c84a83

Browse files
committed
fix: fixed table generation
1 parent 6186dfa commit 3c84a83

File tree

6 files changed

+24
-35
lines changed

6 files changed

+24
-35
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Fixed
2+
body: Fixed table generation
3+
time: 2025-07-04T11:37:33.635807967+02:00

internal/cmd/cloudcmd/api_client.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ var listApiClientCmd = &cobra.Command{
6161
}
6262
}
6363

64-
writeTable(os.Stdout,
64+
return writeTable(os.Stdout,
6565
[]string{"Created At", "ClientWrapper ID", "ClientWrapper Secret", "Last Used", "Description", "Scopes"},
6666
data,
6767
)
68-
return nil
6968
},
7069
}
7170

internal/cmd/cloudcmd/component.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ var componentListCmd = &cobra.Command{
7878
}
7979
}
8080

81-
writeTable(os.Stdout,
81+
return writeTable(os.Stdout,
8282
[]string{"Created At", "Key"},
8383
data,
8484
)
85-
return nil
8685
},
8786
}
8887

@@ -209,12 +208,10 @@ var componentListVersionCmd = &cobra.Command{
209208
}
210209
}
211210

212-
writeTable(os.Stdout,
211+
return writeTable(os.Stdout,
213212
[]string{"Created At", "Key"},
214213
data,
215214
)
216-
217-
return nil
218215
},
219216
}
220217

@@ -252,12 +249,10 @@ var componentDescribeVersionCmd = &cobra.Command{
252249
}
253250
}
254251

255-
writeTable(os.Stdout,
252+
return writeTable(os.Stdout,
256253
[]string{"Date", "Commit", "Author", "Message"},
257254
data,
258255
)
259-
260-
return nil
261256
},
262257
}
263258

internal/cmd/cloudcmd/organization.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ var listOrganizationCmd = &cobra.Command{
3535
record.Key,
3636
}
3737
}
38-
writeTable(os.Stdout, []string{"Created At", "Name", "Key"}, data)
39-
return nil
38+
return writeTable(os.Stdout, []string{"Created At", "Name", "Key"}, data)
4039
},
4140
}
4241

internal/cmd/cloudcmd/project.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ var listProjectCmd = &cobra.Command{
3636
record.Key,
3737
}
3838
}
39-
writeTable(os.Stdout, []string{"Created At", "Name", "Key"}, data)
40-
return nil
39+
return writeTable(os.Stdout, []string{"Created At", "Name", "Key"}, data)
4140
},
4241
}
4342

internal/cmd/cloudcmd/utils.go

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package cloudcmd
22

33
import (
4-
"fmt"
5-
"io"
6-
"os"
7-
84
"github.com/olekukonko/tablewriter"
5+
"github.com/olekukonko/tablewriter/tw"
96
"github.com/spf13/cobra"
7+
"io"
108
)
119

1210
func Must(err error) {
@@ -23,21 +21,17 @@ func MustGetString(cmd *cobra.Command, key string) string {
2321
return value
2422
}
2523

26-
func writeTable(writer io.Writer, header []string, data [][]string) {
27-
table := tablewriter.NewWriter(os.Stdout)
28-
table.SetAutoWrapText(false)
29-
table.SetAutoFormatHeaders(true)
30-
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
31-
table.SetAlignment(tablewriter.ALIGN_LEFT)
32-
table.SetCenterSeparator("")
33-
table.SetColumnSeparator("")
34-
table.SetRowSeparator("-")
35-
table.SetHeaderLine(true)
36-
table.SetBorder(true)
37-
table.SetTablePadding("\t") // pad with tabs
38-
table.SetNoWhiteSpace(true)
39-
table.SetHeader(header)
40-
table.AppendBulk(data)
41-
table.Render() // Send output
42-
fmt.Println()
24+
func writeTable(writer io.Writer, header []string, data [][]string) error {
25+
table := tablewriter.NewWriter(writer)
26+
table.Configure(func(cfg *tablewriter.Config) {
27+
cfg.Row.Formatting.AutoWrap = tw.WrapNone
28+
cfg.Header.Formatting.AutoFormat = tw.On
29+
cfg.Header.Alignment.Global = tw.AlignLeft
30+
cfg.Row.Alignment.Global = tw.AlignLeft
31+
cfg.Behavior.TrimSpace = tw.On
32+
})
33+
table.Header(header)
34+
_ = table.Bulk(data)
35+
36+
return table.Render()
4337
}

0 commit comments

Comments
 (0)