Skip to content

Commit ab06102

Browse files
committed
Add option to remove table boarder for the output
--- ### Master issue #1237 ### Motivation Support output the table without boarder line
1 parent 2a27bec commit ab06102

File tree

18 files changed

+31
-2
lines changed

18 files changed

+31
-2
lines changed

pkg/cmdutils/output.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package cmdutils
2020
import (
2121
"encoding/json"
2222
"fmt"
23+
"github.com/olekukonko/tablewriter"
2324
"io"
2425

2526
"github.com/ghodss/yaml"
@@ -32,6 +33,8 @@ import (
3233
type OutputConfig struct {
3334
// the output format (Table, Plain, Json, Yaml)
3435
Format string
36+
37+
noBoarder bool
3538
}
3639

3740
// AddTo registers the output flagset into a group
@@ -43,9 +46,18 @@ func (c *OutputConfig) AddTo(group *NamedFlagSetGroup) {
4346
"o",
4447
string(TextOutputFormat),
4548
"The output format (text,json,yaml)")
49+
flags.BoolVar(&c.noBoarder, "no-boarder", false, "Whether have board for the output table")
4650
})
4751
}
4852

53+
func (c *OutputConfig) TableConfig(table *tablewriter.Table) {
54+
if c.noBoarder {
55+
table.SetBorder(false)
56+
table.SetHeaderLine(false)
57+
table.SetColumnSeparator("\t")
58+
}
59+
}
60+
4961
// WriteOutput writes output based on the configured output format and on available content
5062
func (c *OutputConfig) WriteOutput(w io.Writer, f OutputNegotiable) error {
5163
ow := f.Negotiate(OutputFormat(c.Format))

pkg/ctl/brokers/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ package brokers
1919

2020
import (
2121
"errors"
22-
"io"
23-
2422
"github.com/olekukonko/tablewriter"
2523
"github.com/streamnative/pulsarctl/pkg/cmdutils"
24+
"io"
2625
)
2726

2827
func getBrokerListCmd(vc *cmdutils.VerbCmd) {
@@ -82,6 +81,7 @@ func doListCluster(vc *cmdutils.VerbCmd) error {
8281
WithObject(brokersData).
8382
WithTextFunc(func(w io.Writer) error {
8483
table := tablewriter.NewWriter(w)
84+
vc.OutputConfig.TableConfig(table)
8585
table.SetHeader([]string{"Brokers List"})
8686

8787
for _, c := range brokersData {

pkg/ctl/brokers/list_dynamic_config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func doGetDynamicConfigListName(vc *cmdutils.VerbCmd) error {
7474
WithObject(nameListData).
7575
WithTextFunc(func(w io.Writer) error {
7676
table := tablewriter.NewWriter(w)
77+
vc.OutputConfig.TableConfig(table)
7778
table.SetHeader([]string{"Dynamic Config Names"})
7879

7980
for _, c := range nameListData {

pkg/ctl/cluster/get_peer_clusters.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func doGetPeerClusters(vc *cmdutils.VerbCmd) error {
7979
WithObject(peerClusters).
8080
WithTextFunc(func(w io.Writer) error {
8181
table := tablewriter.NewWriter(w)
82+
vc.OutputConfig.TableConfig(table)
8283
table.SetHeader([]string{"Peer clusters"})
8384

8485
for _, c := range peerClusters {

pkg/ctl/cluster/list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func doListClusters(vc *cmdutils.VerbCmd) error {
7979
WithObject(clusters).
8080
WithTextFunc(func(w io.Writer) error {
8181
table := tablewriter.NewWriter(w)
82+
vc.OutputConfig.TableConfig(table)
8283
table.SetHeader([]string{"Cluster Name"})
8384

8485
for _, c := range clusters {

pkg/ctl/functions/list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func doListFunctions(vc *cmdutils.VerbCmd, funcData *utils.FunctionData) error {
102102
WithObject(functions).
103103
WithTextFunc(func(w io.Writer) error {
104104
table := tablewriter.NewWriter(w)
105+
vc.OutputConfig.TableConfig(table)
105106
table.SetHeader([]string{"Pulsar Function Name"})
106107

107108
for _, f := range functions {

pkg/ctl/namespace/list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func doListNamespaces(vc *cmdutils.VerbCmd) error {
9090
WithObject(listNamespaces).
9191
WithTextFunc(func(w io.Writer) error {
9292
table := tablewriter.NewWriter(w)
93+
vc.OutputConfig.TableConfig(table)
9394
table.SetHeader([]string{"Namespace Name"})
9495
for _, ns := range listNamespaces {
9596
table.Append([]string{ns})

pkg/ctl/namespace/topics.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func doListTopics(vc *cmdutils.VerbCmd) error {
9393
WithObject(listTopics).
9494
WithTextFunc(func(w io.Writer) error {
9595
table := tablewriter.NewWriter(w)
96+
vc.OutputConfig.TableConfig(table)
9697
table.SetHeader([]string{"Topics Name"})
9798
for _, topic := range listTopics {
9899
table.Append([]string{topic})

pkg/ctl/packages/list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func doListPackages(vc *cmdutils.VerbCmd, packageType string) error {
100100
WithObject(packages).
101101
WithTextFunc(func(w io.Writer) error {
102102
table := tablewriter.NewWriter(w)
103+
vc.OutputConfig.TableConfig(table)
103104
table.SetHeader([]string{"Pulsar Package Name"})
104105

105106
for _, f := range packages {

pkg/ctl/packages/list_versions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func doListPackageVersions(vc *cmdutils.VerbCmd) error {
8787
WithObject(packages).
8888
WithTextFunc(func(w io.Writer) error {
8989
table := tablewriter.NewWriter(w)
90+
vc.OutputConfig.TableConfig(table)
9091
table.SetHeader([]string{"Pulsar Package Version"})
9192

9293
for _, f := range packages {

pkg/ctl/plugin/list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func doListPlugins(vc *cmdutils.VerbCmd) error {
9393
WithObject(plugins).
9494
WithTextFunc(func(w io.Writer) error {
9595
table := tablewriter.NewWriter(w)
96+
vc.OutputConfig.TableConfig(table)
9697
table.SetHeader([]string{"plugins"})
9798
for _, v := range plugins {
9899
table.Append([]string{v})

pkg/ctl/sinks/list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func doListSinks(vc *cmdutils.VerbCmd, sinkData *utils.SinkData) error {
102102
WithObject(sinks).
103103
WithTextFunc(func(w io.Writer) error {
104104
table := tablewriter.NewWriter(w)
105+
vc.OutputConfig.TableConfig(table)
105106
table.SetHeader([]string{"Pulsar Sinks Name"})
106107

107108
for _, f := range sinks {

pkg/ctl/sinks/list_built_in_sinks.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func doListBuiltInSinks(vc *cmdutils.VerbCmd) error {
7979
WithObject(connectorDefinition).
8080
WithTextFunc(func(w io.Writer) error {
8181
table := tablewriter.NewWriter(w)
82+
vc.OutputConfig.TableConfig(table)
8283
table.SetHeader([]string{"Name", "Description", "ClassName"})
8384

8485
for _, f := range connectorDefinition {

pkg/ctl/sources/list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func doListSources(vc *cmdutils.VerbCmd, sourceData *utils.SourceData) error {
102102
WithObject(sources).
103103
WithTextFunc(func(w io.Writer) error {
104104
table := tablewriter.NewWriter(w)
105+
vc.OutputConfig.TableConfig(table)
105106
table.SetHeader([]string{"Pulsar Sources Name"})
106107

107108
for _, f := range sources {

pkg/ctl/sources/list_built_in_sources.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func doListBuiltInSources(vc *cmdutils.VerbCmd) error {
8080
WithObject(connectorDefinition).
8181
WithTextFunc(func(w io.Writer) error {
8282
table := tablewriter.NewWriter(w)
83+
vc.OutputConfig.TableConfig(table)
8384
table.SetHeader([]string{"Name", "Description", "ClassName"})
8485

8586
for _, f := range connectorDefinition {

pkg/ctl/subscription/list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func doList(vc *cmdutils.VerbCmd) error {
8989
WithObject(r).
9090
WithTextFunc(func(w io.Writer) error {
9191
table := tablewriter.NewWriter(w)
92+
vc.OutputConfig.TableConfig(table)
9293
table.SetHeader([]string{"Subscriptions"})
9394
for _, v := range r {
9495
table.Append([]string{v})

pkg/ctl/tenant/list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func doListTenant(vc *cmdutils.VerbCmd) error {
7575
WithObject(tenants).
7676
WithTextFunc(func(w io.Writer) error {
7777
table := tablewriter.NewWriter(w)
78+
vc.OutputConfig.TableConfig(table)
7879
table.SetHeader([]string{"Tenant Name"})
7980

8081
for _, t := range tenants {

pkg/ctl/topic/list.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ func doListTopics(vc *cmdutils.VerbCmd) error {
9090
WithObject(listOutput{partitionedTopics, nonPartitionedTopics}).
9191
WithTextFunc(func(w io.Writer) error {
9292
table := tablewriter.NewWriter(w)
93+
vc.OutputConfig.TableConfig(table)
94+
vc.OutputConfig.TableConfig(table)
9395
table.SetHeader([]string{"topic name", "partitioned ?"})
9496

9597
for _, v := range partitionedTopics {

0 commit comments

Comments
 (0)