Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to remove table boarder for the output #1240

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions pkg/ctl/topic/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func doListTopics(vc *cmdutils.VerbCmd) error {
WithObject(listOutput{partitionedTopics, nonPartitionedTopics}).
WithTextFunc(func(w io.Writer) error {
table := tablewriter.NewWriter(w)
vc.OutputConfig.TableConfig(table)
zymap marked this conversation as resolved.
Show resolved Hide resolved
table.SetHeader([]string{"topic name", "partitioned ?"})

for _, v := range partitionedTopics {
Expand Down
Loading