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

fix(cli): Do not show headers when listing empty lists #53

Merged
merged 3 commits into from
Feb 11, 2021
Merged
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ PRIVATE_REPOS = github.com/meroxa/meroxa-go
.PHONY: gomod
gomod:
GOPRIVATE=$(PRIVATE_REPOS) go mod tidy && go mod vendor

.PHONY: test
test:
go test -v ${GO_TEST_FLAGS} -count=1 ./...
2 changes: 1 addition & 1 deletion cmd/completion.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cmd

import (
"os"
"github.com/spf13/cobra"
"os"
)

// completionCmd represents the completion command
Expand Down
150 changes: 73 additions & 77 deletions cmd/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,84 +32,78 @@ func prettyPrint(section string, data interface{}) {
}

func printResourcesTable(resources []*meroxa.Resource) {
table := simpletable.New()
if len(resources) != 0 {
table := simpletable.New()
table.Header = &simpletable.Header{
Cells: []*simpletable.Cell{
{Align: simpletable.AlignCenter, Text: "ID"},
{Align: simpletable.AlignCenter, Text: "TYPE"},
{Align: simpletable.AlignCenter, Text: "NAME"},
{Align: simpletable.AlignCenter, Text: "URL"},
},
}

table.Header = &simpletable.Header{
Cells: []*simpletable.Cell{
{Align: simpletable.AlignCenter, Text: "ID"},
{Align: simpletable.AlignCenter, Text: "TYPE"},
{Align: simpletable.AlignCenter, Text: "NAME"},
{Align: simpletable.AlignCenter, Text: "URL"},
},
}
for _, res := range resources {
r := []*simpletable.Cell{
{Align: simpletable.AlignRight, Text: fmt.Sprintf("%d", res.ID)},
{Text: res.Kind},
{Text: res.Name},
{Text: res.URL},
}

for _, res := range resources {
r := []*simpletable.Cell{
{Align: simpletable.AlignRight, Text: fmt.Sprintf("%d", res.ID)},
{Text: res.Kind},
{Text: res.Name},
{Text: res.URL},
table.Body.Cells = append(table.Body.Cells, r)
}

table.Body.Cells = append(table.Body.Cells, r)
table.SetStyle(simpletable.StyleCompact)
fmt.Println(table.String())
}
table.SetStyle(simpletable.StyleCompact)
fmt.Println(table.String())
}

func appendCell(cells []*simpletable.Cell, text string) []*simpletable.Cell {
cells = append(cells, &simpletable.Cell{
Align: simpletable.AlignCenter,
Text: text,
})
return cells
}

func printConnectorsTable(connectors []*meroxa.Connector) {
table := simpletable.New()

table.Header = &simpletable.Header{
Cells: []*simpletable.Cell{
{Align: simpletable.AlignCenter, Text: "ID"},
{Align: simpletable.AlignCenter, Text: "TYPE"},
{Align: simpletable.AlignCenter, Text: "NAME"},
{Align: simpletable.AlignCenter, Text: "STREAMS"},
{Align: simpletable.AlignCenter, Text: "STATE"},
},
}
if len(connectors) != 0 {
table := simpletable.New()
table.Header = &simpletable.Header{
Cells: []*simpletable.Cell{
{Align: simpletable.AlignCenter, Text: "ID"},
{Align: simpletable.AlignCenter, Text: "TYPE"},
{Align: simpletable.AlignCenter, Text: "NAME"},
{Align: simpletable.AlignCenter, Text: "STREAMS"},
{Align: simpletable.AlignCenter, Text: "STATE"},
},
}

for _, conn := range connectors {
var streamStr string
for _, conn := range connectors {
var streamStr string

if streamInput, ok := conn.Streams["input"]; ok {
streamStr += "input:\n"
if streamInput, ok := conn.Streams["input"]; ok {
streamStr += "input:\n"

streamInterface := streamInput.([]interface{})
for _, v := range streamInterface {
streamStr += fmt.Sprintf("%v\n", v)
streamInterface := streamInput.([]interface{})
for _, v := range streamInterface {
streamStr += fmt.Sprintf("%v\n", v)
}
}
}

if streamOutput, ok := conn.Streams["output"]; ok {
streamStr += "output:\n"
if streamOutput, ok := conn.Streams["output"]; ok {
streamStr += "output:\n"

streamInterface := streamOutput.([]interface{})
for _, v := range streamInterface {
streamStr += fmt.Sprintf("%v\n", v)
streamInterface := streamOutput.([]interface{})
for _, v := range streamInterface {
streamStr += fmt.Sprintf("%v\n", v)
}
}
r := []*simpletable.Cell{
{Align: simpletable.AlignRight, Text: fmt.Sprintf("%d", conn.ID)},
{Text: conn.Kind},
{Text: conn.Name},
{Text: streamStr},
{Text: conn.State},
}
}
r := []*simpletable.Cell{
{Align: simpletable.AlignRight, Text: fmt.Sprintf("%d", conn.ID)},
{Text: conn.Kind},
{Text: conn.Name},
{Text: streamStr},
{Text: conn.State},
}

table.Body.Cells = append(table.Body.Cells, r)
table.Body.Cells = append(table.Body.Cells, r)
}
table.SetStyle(simpletable.StyleCompact)
fmt.Println(table.String())
}
table.SetStyle(simpletable.StyleCompact)
fmt.Println(table.String())
}

func printResourceTypesTable(types []string) {
Expand All @@ -133,23 +127,25 @@ func printResourceTypesTable(types []string) {
}

func printPipelinesTable(pipelines []*meroxa.Pipeline) {
table := simpletable.New()
if len(pipelines) != 0 {
table := simpletable.New()

table.Header = &simpletable.Header{
Cells: []*simpletable.Cell{
{Align: simpletable.AlignCenter, Text: "ID"},
{Align: simpletable.AlignCenter, Text: "Name"},
},
}

table.Header = &simpletable.Header{
Cells: []*simpletable.Cell{
{Align: simpletable.AlignCenter, Text: "ID"},
{Align: simpletable.AlignCenter, Text: "Name"},
},
}
for _, p := range pipelines {
r := []*simpletable.Cell{
{Align: simpletable.AlignRight, Text: strconv.Itoa(p.ID)},
{Align: simpletable.AlignCenter, Text: p.Name},
}

for _, p := range pipelines {
r := []*simpletable.Cell{
{Align: simpletable.AlignRight, Text: strconv.Itoa(p.ID)},
{Align: simpletable.AlignCenter, Text: p.Name},
table.Body.Cells = append(table.Body.Cells, r)
}

table.Body.Cells = append(table.Body.Cells, r)
table.SetStyle(simpletable.StyleCompact)
fmt.Println(table.String())
}
table.SetStyle(simpletable.StyleCompact)
fmt.Println(table.String())
}
30 changes: 29 additions & 1 deletion cmd/display_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,39 @@ func TestResourcesTable(t *testing.T) {
}
}
fmt.Println(out)

})
}
}

func TestEmptyTables(t *testing.T) {
emptyResourcesList := []*meroxa.Resource{}
out := captureOutput(func() {
printResourcesTable(emptyResourcesList)
})

if out != "" {
t.Errorf("Output for resources should be blank")
}

emptyConnectorsList := []*meroxa.Connector{}
out = captureOutput(func() {
printConnectorsTable(emptyConnectorsList)
})

if out != "" {
t.Errorf("Output for connectors should be blank")
}

emptyPipelinesList := []*meroxa.Pipeline{}

out = captureOutput(func() {
printPipelinesTable(emptyPipelinesList)
})

if out != "" {
t.Errorf("Output for pipelines should be blank")
}
}
func TestResourceTypesTable(t *testing.T) {
types := []string{"postgres", "s3", "redshift", "mysql", "jdbc", "url", "mongodb"}
printResourceTypesTable(types)
Expand Down