Skip to content

Commit 31302fe

Browse files
committed
chore(routes): format output
1 parent eadba19 commit 31302fe

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

cmd/routes.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package cmd
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"os"
6-
"strings"
77

88
"github.com/drycc/controller-sdk-go/api"
99
"github.com/drycc/controller-sdk-go/routes"
@@ -49,7 +49,7 @@ func (d *DryccCmd) RoutesList(appID string, results int) error {
4949
if count == 0 {
5050
d.Println(fmt.Sprintf("No routes found in %s app.", appID))
5151
} else {
52-
table := d.getDefaultFormatTable([]string{"NAME", "OWNER", "KIND", "GATEWAY", "SERVICE"})
52+
table := d.getDefaultFormatTable([]string{"NAME", "OWNER", "KIND", "GATEWAYS", "SERVICES"})
5353
for _, route := range routes {
5454
var services []string
5555
for _, rule := range route.Rules {
@@ -65,13 +65,15 @@ func (d *DryccCmd) RoutesList(appID string, results int) error {
6565
for _, gateway := range route.ParentRefs {
6666
gateways = append(gateways, fmt.Sprintf("%s:%d", gateway.Name, gateway.Port))
6767
}
68-
table.Append([]string{
69-
route.Name,
70-
route.Owner,
71-
route.Kind,
72-
safeGetString(strings.Join(gateways, "\n")),
73-
safeGetString(strings.Join(services, "\n")),
74-
})
68+
gatewaysBytes, err := json.Marshal(gateways)
69+
if err != nil {
70+
return err
71+
}
72+
servicesBytes, err := json.Marshal(services)
73+
if err != nil {
74+
return err
75+
}
76+
table.Append([]string{route.Name, route.Owner, route.Kind, string(gatewaysBytes), string(servicesBytes)})
7577
}
7678
table.Render()
7779
}

cmd/routes_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@ func TestRoutesList(t *testing.T) {
103103
err = cmdr.RoutesList("foo", -1)
104104
assert.NoError(t, err)
105105

106-
assert.Equal(t, b.String(), `NAME OWNER KIND GATEWAY SERVICE
107-
example-go test HTTPRoute example-go:80 yygl-nextcloud:80
108-
example-go:8080 yygl-nextcloud:8080
106+
assert.Equal(t, b.String(), `NAME OWNER KIND GATEWAYS SERVICES
107+
example-go test HTTPRoute ["example-go:80","example-go:8080"] ["yygl-nextcloud:80","yygl-nextcloud:8080"]
109108
`, "output")
110109
}
111110

0 commit comments

Comments
 (0)