diff --git a/pkg/cmdutils/output.go b/pkg/cmdutils/output.go index 1555a30a..c8631018 100644 --- a/pkg/cmdutils/output.go +++ b/pkg/cmdutils/output.go @@ -23,6 +23,7 @@ import ( "io" "github.com/ghodss/yaml" + "github.com/olekukonko/tablewriter" "github.com/spf13/pflag" ) @@ -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 @@ -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)) diff --git a/pkg/ctl/brokers/list.go b/pkg/ctl/brokers/list.go index 05008ac8..eb27baff 100644 --- a/pkg/ctl/brokers/list.go +++ b/pkg/ctl/brokers/list.go @@ -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 { diff --git a/pkg/ctl/brokers/list_dynamic_config.go b/pkg/ctl/brokers/list_dynamic_config.go index d12ef333..98c53ea6 100644 --- a/pkg/ctl/brokers/list_dynamic_config.go +++ b/pkg/ctl/brokers/list_dynamic_config.go @@ -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 { diff --git a/pkg/ctl/cluster/get_peer_clusters.go b/pkg/ctl/cluster/get_peer_clusters.go index ce35a989..a0138947 100644 --- a/pkg/ctl/cluster/get_peer_clusters.go +++ b/pkg/ctl/cluster/get_peer_clusters.go @@ -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 { diff --git a/pkg/ctl/cluster/list.go b/pkg/ctl/cluster/list.go index badd0d10..6d2da156 100644 --- a/pkg/ctl/cluster/list.go +++ b/pkg/ctl/cluster/list.go @@ -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 { diff --git a/pkg/ctl/functions/list.go b/pkg/ctl/functions/list.go index 68852d5e..3292ae30 100644 --- a/pkg/ctl/functions/list.go +++ b/pkg/ctl/functions/list.go @@ -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 { diff --git a/pkg/ctl/namespace/list.go b/pkg/ctl/namespace/list.go index bae105fc..3f3b6e2a 100644 --- a/pkg/ctl/namespace/list.go +++ b/pkg/ctl/namespace/list.go @@ -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}) diff --git a/pkg/ctl/namespace/topics.go b/pkg/ctl/namespace/topics.go index 876d74cf..b3d87047 100644 --- a/pkg/ctl/namespace/topics.go +++ b/pkg/ctl/namespace/topics.go @@ -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}) diff --git a/pkg/ctl/packages/list.go b/pkg/ctl/packages/list.go index b7d142c6..ea3a0e1f 100644 --- a/pkg/ctl/packages/list.go +++ b/pkg/ctl/packages/list.go @@ -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 { diff --git a/pkg/ctl/packages/list_versions.go b/pkg/ctl/packages/list_versions.go index aa6ab874..fc60ee38 100644 --- a/pkg/ctl/packages/list_versions.go +++ b/pkg/ctl/packages/list_versions.go @@ -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 { diff --git a/pkg/ctl/plugin/list.go b/pkg/ctl/plugin/list.go index bc973640..432191ce 100644 --- a/pkg/ctl/plugin/list.go +++ b/pkg/ctl/plugin/list.go @@ -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}) diff --git a/pkg/ctl/sinks/list.go b/pkg/ctl/sinks/list.go index 08aa8c6a..4f11daf0 100644 --- a/pkg/ctl/sinks/list.go +++ b/pkg/ctl/sinks/list.go @@ -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 { diff --git a/pkg/ctl/sinks/list_built_in_sinks.go b/pkg/ctl/sinks/list_built_in_sinks.go index 0f38981b..86ae8aa3 100644 --- a/pkg/ctl/sinks/list_built_in_sinks.go +++ b/pkg/ctl/sinks/list_built_in_sinks.go @@ -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 { diff --git a/pkg/ctl/sources/list.go b/pkg/ctl/sources/list.go index 62051086..916e2074 100644 --- a/pkg/ctl/sources/list.go +++ b/pkg/ctl/sources/list.go @@ -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 { diff --git a/pkg/ctl/sources/list_built_in_sources.go b/pkg/ctl/sources/list_built_in_sources.go index d51a7b95..2f23783d 100644 --- a/pkg/ctl/sources/list_built_in_sources.go +++ b/pkg/ctl/sources/list_built_in_sources.go @@ -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 { diff --git a/pkg/ctl/subscription/list.go b/pkg/ctl/subscription/list.go index f5196cc3..7b0a111d 100644 --- a/pkg/ctl/subscription/list.go +++ b/pkg/ctl/subscription/list.go @@ -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}) diff --git a/pkg/ctl/tenant/list.go b/pkg/ctl/tenant/list.go index dd5dd245..67517f38 100644 --- a/pkg/ctl/tenant/list.go +++ b/pkg/ctl/tenant/list.go @@ -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 { diff --git a/pkg/ctl/topic/list.go b/pkg/ctl/topic/list.go index 2a189e98..f374ada7 100644 --- a/pkg/ctl/topic/list.go +++ b/pkg/ctl/topic/list.go @@ -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) table.SetHeader([]string{"topic name", "partitioned ?"}) for _, v := range partitionedTopics {