Skip to content

Commit

Permalink
Formatter is unhelpful and makes things difficult to copy & paste (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
janelletavares authored Apr 8, 2022
1 parent 4111970 commit 4640356
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
25 changes: 10 additions & 15 deletions utils/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@ import (
"strconv"
"strings"

"golang.org/x/text/cases"
"golang.org/x/text/language"

"github.com/alexeyco/simpletable"
"github.com/meroxa/meroxa-go/pkg/meroxa"
)

var formatter = cases.Title(language.Und, cases.NoLower)

func EndpointsTable(ends []meroxa.Endpoint, hideHeaders bool) string {
if len(ends) == 0 {
return ""
Expand Down Expand Up @@ -54,7 +49,7 @@ func EndpointsTable(ends []meroxa.Endpoint, hideHeaders bool) string {
{Text: string(end.Protocol)},
{Text: end.Stream},
{Text: u},
{Text: formatter.String(strconv.FormatBool(end.Ready))},
{Text: strconv.FormatBool(end.Ready)},
}

table.Body.Cells = append(table.Body.Cells, r)
Expand Down Expand Up @@ -94,14 +89,14 @@ func ResourceTable(res *meroxa.Resource) string {
},
{
{Align: simpletable.AlignRight, Text: "State:"},
{Text: formatter.String(string(res.Status.State))},
{Text: string(res.Status.State)},
},
}

if d := res.Status.Details; d != "" {
if res.Status.Details != "" {
mainTable.Body.Cells = append(mainTable.Body.Cells, []*simpletable.Cell{
{Align: simpletable.AlignRight, Text: "State details:"},
{Text: formatter.String(d)},
{Text: res.Status.Details},
})
}

Expand Down Expand Up @@ -166,7 +161,7 @@ func PipelineTable(p *meroxa.Pipeline) string {

mainTable.Body.Cells = append(mainTable.Body.Cells, []*simpletable.Cell{
{Align: simpletable.AlignRight, Text: "State:"},
{Text: formatter.String(string(p.State))},
{Text: string(p.State)},
})

mainTable.SetStyle(simpletable.StyleCompact)
Expand Down Expand Up @@ -217,7 +212,7 @@ func ResourcesTable(resources []*meroxa.Resource, hideHeaders bool) string {
{Text: env},
{Text: res.URL},
{Align: simpletable.AlignCenter, Text: tunnel},
{Align: simpletable.AlignCenter, Text: formatter.String(string(res.Status.State))},
{Align: simpletable.AlignCenter, Text: string(res.Status.State)},
}

table.Body.Cells = append(table.Body.Cells, r)
Expand Down Expand Up @@ -568,7 +563,7 @@ func FunctionTable(fun *meroxa.Function) string {
},
{
{Align: simpletable.AlignRight, Text: "State:"},
{Text: formatter.String(fun.Status.State)},
{Text: fun.Status.State},
},
}
mainTable.SetStyle(simpletable.StyleCompact)
Expand Down Expand Up @@ -865,15 +860,15 @@ func AppTable(app *meroxa.Application) string {
},
{
{Align: simpletable.AlignRight, Text: "State:"},
{Text: formatter.String(string(app.Status.State))},
{Text: string(app.Status.State)},
},
}

details := app.Status.Details
if details != "" {
mainTable.Body.Cells = append(mainTable.Body.Cells, []*simpletable.Cell{
{Align: simpletable.AlignRight, Text: "State details:"},
{Text: formatter.String(details)},
{Text: details},
})
}

Expand Down Expand Up @@ -911,7 +906,7 @@ func ExtendedAppTable(app *meroxa.Application, resources []*meroxa.Resource, con
},
{
{Align: simpletable.AlignRight, Text: "State:"},
{Text: formatter.String(string(app.Status.State))},
{Text: string(app.Status.State)},
},
}
mainTable.SetStyle(simpletable.StyleCompact)
Expand Down
6 changes: 3 additions & 3 deletions utils/display_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestResourcesTable(t *testing.T) {
if !strings.Contains(out, resource.UUID) {
t.Errorf("%s, not found", resource.UUID)
}
if !strings.Contains(out, formatter.String(string(resource.Status.State))) {
if !strings.Contains(out, string(resource.Status.State)) {
t.Errorf("state %s, not found", resource.Status.State)
}
case "ID_Alignment":
Expand All @@ -72,7 +72,7 @@ func TestResourcesTable(t *testing.T) {
if !strings.Contains(out, resIDAlign.UUID) {
t.Errorf("%s, not found", resIDAlign.UUID)
}
if !strings.Contains(out, formatter.String(string(resIDAlign.Status.State))) {
if !strings.Contains(out, string(resIDAlign.Status.State)) {
t.Errorf("state %s, not found", resource.Status.State)
}
}
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestResourcesTableWithoutHeaders(t *testing.T) {
if !strings.Contains(out, resource.UUID) {
t.Errorf("%s, not found", resource.UUID)
}
if !strings.Contains(out, formatter.String(string(resource.Status.State))) {
if !strings.Contains(out, string(resource.Status.State)) {
t.Errorf("state %s, not found", resource.Status.State)
}
}
Expand Down

0 comments on commit 4640356

Please sign in to comment.