Skip to content

Commit

Permalink
Add option to remove table boarder for the output
Browse files Browse the repository at this point in the history
---

### Master issue
#1237

### Motivation
Support output the table without boarder line
  • Loading branch information
zymap committed Oct 18, 2023
1 parent 2a27bec commit ebc0c86
Show file tree
Hide file tree
Showing 18 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/cmdutils/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io"

"github.com/ghodss/yaml"
"github.com/olekukonko/tablewriter"
"github.com/spf13/pflag"
)

Expand All @@ -32,6 +33,8 @@ import (
type OutputConfig struct {
// the output format (Table, Plain, Json, Yaml)
Format string

noBoarder bool
}

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

func (c *OutputConfig) TableConfig(table *tablewriter.Table) {
if c.noBoarder {
table.SetBorder(false)
table.SetHeaderLine(false)
table.SetColumnSeparator("\t")
}
}

// WriteOutput writes output based on the configured output format and on available content
func (c *OutputConfig) WriteOutput(w io.Writer, f OutputNegotiable) error {
ow := f.Negotiate(OutputFormat(c.Format))
Expand Down
1 change: 1 addition & 0 deletions pkg/ctl/brokers/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func doListCluster(vc *cmdutils.VerbCmd) error {
WithObject(brokersData).
WithTextFunc(func(w io.Writer) error {
table := tablewriter.NewWriter(w)
vc.OutputConfig.TableConfig(table)
table.SetHeader([]string{"Brokers List"})

for _, c := range brokersData {
Expand Down
1 change: 1 addition & 0 deletions pkg/ctl/brokers/list_dynamic_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func doGetDynamicConfigListName(vc *cmdutils.VerbCmd) error {
WithObject(nameListData).
WithTextFunc(func(w io.Writer) error {
table := tablewriter.NewWriter(w)
vc.OutputConfig.TableConfig(table)
table.SetHeader([]string{"Dynamic Config Names"})

for _, c := range nameListData {
Expand Down
1 change: 1 addition & 0 deletions pkg/ctl/cluster/get_peer_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func doGetPeerClusters(vc *cmdutils.VerbCmd) error {
WithObject(peerClusters).
WithTextFunc(func(w io.Writer) error {
table := tablewriter.NewWriter(w)
vc.OutputConfig.TableConfig(table)
table.SetHeader([]string{"Peer clusters"})

for _, c := range peerClusters {
Expand Down
1 change: 1 addition & 0 deletions pkg/ctl/cluster/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func doListClusters(vc *cmdutils.VerbCmd) error {
WithObject(clusters).
WithTextFunc(func(w io.Writer) error {
table := tablewriter.NewWriter(w)
vc.OutputConfig.TableConfig(table)
table.SetHeader([]string{"Cluster Name"})

for _, c := range clusters {
Expand Down
1 change: 1 addition & 0 deletions pkg/ctl/functions/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func doListFunctions(vc *cmdutils.VerbCmd, funcData *utils.FunctionData) error {
WithObject(functions).
WithTextFunc(func(w io.Writer) error {
table := tablewriter.NewWriter(w)
vc.OutputConfig.TableConfig(table)
table.SetHeader([]string{"Pulsar Function Name"})

for _, f := range functions {
Expand Down
1 change: 1 addition & 0 deletions pkg/ctl/namespace/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func doListNamespaces(vc *cmdutils.VerbCmd) error {
WithObject(listNamespaces).
WithTextFunc(func(w io.Writer) error {
table := tablewriter.NewWriter(w)
vc.OutputConfig.TableConfig(table)
table.SetHeader([]string{"Namespace Name"})
for _, ns := range listNamespaces {
table.Append([]string{ns})
Expand Down
1 change: 1 addition & 0 deletions pkg/ctl/namespace/topics.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func doListTopics(vc *cmdutils.VerbCmd) error {
WithObject(listTopics).
WithTextFunc(func(w io.Writer) error {
table := tablewriter.NewWriter(w)
vc.OutputConfig.TableConfig(table)
table.SetHeader([]string{"Topics Name"})
for _, topic := range listTopics {
table.Append([]string{topic})
Expand Down
1 change: 1 addition & 0 deletions pkg/ctl/packages/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func doListPackages(vc *cmdutils.VerbCmd, packageType string) error {
WithObject(packages).
WithTextFunc(func(w io.Writer) error {
table := tablewriter.NewWriter(w)
vc.OutputConfig.TableConfig(table)
table.SetHeader([]string{"Pulsar Package Name"})

for _, f := range packages {
Expand Down
1 change: 1 addition & 0 deletions pkg/ctl/packages/list_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func doListPackageVersions(vc *cmdutils.VerbCmd) error {
WithObject(packages).
WithTextFunc(func(w io.Writer) error {
table := tablewriter.NewWriter(w)
vc.OutputConfig.TableConfig(table)
table.SetHeader([]string{"Pulsar Package Version"})

for _, f := range packages {
Expand Down
1 change: 1 addition & 0 deletions pkg/ctl/plugin/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func doListPlugins(vc *cmdutils.VerbCmd) error {
WithObject(plugins).
WithTextFunc(func(w io.Writer) error {
table := tablewriter.NewWriter(w)
vc.OutputConfig.TableConfig(table)
table.SetHeader([]string{"plugins"})
for _, v := range plugins {
table.Append([]string{v})
Expand Down
1 change: 1 addition & 0 deletions pkg/ctl/sinks/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func doListSinks(vc *cmdutils.VerbCmd, sinkData *utils.SinkData) error {
WithObject(sinks).
WithTextFunc(func(w io.Writer) error {
table := tablewriter.NewWriter(w)
vc.OutputConfig.TableConfig(table)
table.SetHeader([]string{"Pulsar Sinks Name"})

for _, f := range sinks {
Expand Down
1 change: 1 addition & 0 deletions pkg/ctl/sinks/list_built_in_sinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func doListBuiltInSinks(vc *cmdutils.VerbCmd) error {
WithObject(connectorDefinition).
WithTextFunc(func(w io.Writer) error {
table := tablewriter.NewWriter(w)
vc.OutputConfig.TableConfig(table)
table.SetHeader([]string{"Name", "Description", "ClassName"})

for _, f := range connectorDefinition {
Expand Down
1 change: 1 addition & 0 deletions pkg/ctl/sources/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func doListSources(vc *cmdutils.VerbCmd, sourceData *utils.SourceData) error {
WithObject(sources).
WithTextFunc(func(w io.Writer) error {
table := tablewriter.NewWriter(w)
vc.OutputConfig.TableConfig(table)
table.SetHeader([]string{"Pulsar Sources Name"})

for _, f := range sources {
Expand Down
1 change: 1 addition & 0 deletions pkg/ctl/sources/list_built_in_sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func doListBuiltInSources(vc *cmdutils.VerbCmd) error {
WithObject(connectorDefinition).
WithTextFunc(func(w io.Writer) error {
table := tablewriter.NewWriter(w)
vc.OutputConfig.TableConfig(table)
table.SetHeader([]string{"Name", "Description", "ClassName"})

for _, f := range connectorDefinition {
Expand Down
1 change: 1 addition & 0 deletions pkg/ctl/subscription/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func doList(vc *cmdutils.VerbCmd) error {
WithObject(r).
WithTextFunc(func(w io.Writer) error {
table := tablewriter.NewWriter(w)
vc.OutputConfig.TableConfig(table)
table.SetHeader([]string{"Subscriptions"})
for _, v := range r {
table.Append([]string{v})
Expand Down
1 change: 1 addition & 0 deletions pkg/ctl/tenant/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func doListTenant(vc *cmdutils.VerbCmd) error {
WithObject(tenants).
WithTextFunc(func(w io.Writer) error {
table := tablewriter.NewWriter(w)
vc.OutputConfig.TableConfig(table)
table.SetHeader([]string{"Tenant Name"})

for _, t := range tenants {
Expand Down
2 changes: 2 additions & 0 deletions pkg/ctl/topic/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ func doListTopics(vc *cmdutils.VerbCmd) error {
WithObject(listOutput{partitionedTopics, nonPartitionedTopics}).
WithTextFunc(func(w io.Writer) error {
table := tablewriter.NewWriter(w)
vc.OutputConfig.TableConfig(table)
vc.OutputConfig.TableConfig(table)
table.SetHeader([]string{"topic name", "partitioned ?"})

for _, v := range partitionedTopics {
Expand Down

0 comments on commit ebc0c86

Please sign in to comment.