Skip to content

Commit

Permalink
feat(router): list static routes in show output
Browse files Browse the repository at this point in the history
  • Loading branch information
kangasta committed Jul 22, 2024
1 parent bd632f2 commit bebc983
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
github.com/UpCloudLtd/progress v1.0.2
github.com/UpCloudLtd/upcloud-go-api/v8 v8.6.2
github.com/UpCloudLtd/upcloud-go-api/v8 v8.6.3-0.20240722122851-ddac0f425718
github.com/adrg/xdg v0.3.2
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/gemalto/flume v0.12.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ github.com/UpCloudLtd/progress v1.0.2 h1:CTr1bBuFuXop9TEhR1PakbUMPTlUVL7Bgae9Jgq
github.com/UpCloudLtd/progress v1.0.2/go.mod h1:iGxOnb9HvHW0yrLGUjHr0lxHhn7TehgWwh7a8NqK6iQ=
github.com/UpCloudLtd/upcloud-go-api/v8 v8.6.2 h1:jmHb2PBA4fbDQRR4WrpD94ncSqQ8EAnzJ7PZS0AmALk=
github.com/UpCloudLtd/upcloud-go-api/v8 v8.6.2/go.mod h1:/BL9bYxio0GCdotzBvZjkpm1fSDtD0+0z6PtNMew9HU=
github.com/UpCloudLtd/upcloud-go-api/v8 v8.6.3-0.20240722122851-ddac0f425718 h1:jkFnrAgeYvwa4GS0xxKKqqRHpBZYAvNShQLbUVOyN1E=
github.com/UpCloudLtd/upcloud-go-api/v8 v8.6.3-0.20240722122851-ddac0f425718/go.mod h1:/BL9bYxio0GCdotzBvZjkpm1fSDtD0+0z6PtNMew9HU=
github.com/adrg/xdg v0.3.2 h1:GUSGQ5pHdev83AYhDSS1A/CX+0JIsxbiWtow2DSA+RU=
github.com/adrg/xdg v0.3.2/go.mod h1:7I2hH/IT30IsupOpKZ5ue7/qNi3CoKzD6tL3HwpaRMQ=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down
23 changes: 23 additions & 0 deletions internal/commands/router/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ func (s *showCommand) Execute(exec commands.Executor, arg string) (output.Output
network.Zone,
}
}
staticRouteRows := make([]output.TableRow, len(router.StaticRoutes))
for i, staticRoute := range router.StaticRoutes {
staticRouteRows[i] = output.TableRow{
staticRoute.Name,
staticRoute.Route,
staticRoute.Nexthop,
staticRoute.Type,
}
}
combined := output.Combined{
output.CombinedSection{
Key: "",
Expand Down Expand Up @@ -84,6 +93,20 @@ func (s *showCommand) Execute(exec commands.Executor, arg string) (output.Output
Rows: networkRows,
},
},
output.CombinedSection{
Key: "static_routes",
Title: "Static routes:",
Contents: output.Table{
Columns: []output.TableColumn{
{Key: "name", Header: "Name"},
{Key: "route", Header: "Route", Colour: ui.DefaultAddressColours},
{Key: "nexthop", Header: "Nexthop", Colour: ui.DefaultAddressColours},
{Key: "type", Header: "Type"},
},
Rows: staticRouteRows,
EmptyMessage: "No static routes defined for this resource.",
},
},
}

return output.MarshaledWithHumanOutput{
Expand Down
4 changes: 4 additions & 0 deletions internal/commands/router/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func TestShowCommand(t *testing.T) {
────────────────────────────────────── ────────────── ───────── ─────────
ce6a9934-c0c6-4d84-9ad4-0611f5b95e79 test-network utility uk-lon1
Static routes:
No static routes defined for this resource.
`
mService := smock.Service{}
mService.On("GetRouters", mock.Anything).Return(&upcloud.Routers{Routers: []upcloud.Router{router}}, nil)
Expand Down

0 comments on commit bebc983

Please sign in to comment.