Skip to content

Commit 554d821

Browse files
authored
feat(router): list static routes in show output (#325)
1 parent d04bb97 commit 554d821

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Add labels to `database show` output.
13+
- In `router show` command, list static routes in the human readable output and add static route type field to all outputs.
1314

1415
## [3.10.0] - 2024-07-17
1516

internal/commands/router/show.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ func (s *showCommand) Execute(exec commands.Executor, arg string) (output.Output
5656
network.Zone,
5757
}
5858
}
59+
staticRouteRows := make([]output.TableRow, len(router.StaticRoutes))
60+
for i, staticRoute := range router.StaticRoutes {
61+
staticRouteRows[i] = output.TableRow{
62+
staticRoute.Name,
63+
staticRoute.Route,
64+
staticRoute.Nexthop,
65+
staticRoute.Type,
66+
}
67+
}
5968
combined := output.Combined{
6069
output.CombinedSection{
6170
Key: "",
@@ -70,7 +79,7 @@ func (s *showCommand) Execute(exec commands.Executor, arg string) (output.Output
7079
},
7180
},
7281
},
73-
labels.GetLabelsSection(router.Labels),
82+
labels.GetLabelsSectionWithResourceType(router.Labels, "router"),
7483
output.CombinedSection{
7584
Key: "networks",
7685
Title: "Networks:",
@@ -84,6 +93,20 @@ func (s *showCommand) Execute(exec commands.Executor, arg string) (output.Output
8493
Rows: networkRows,
8594
},
8695
},
96+
output.CombinedSection{
97+
Key: "static_routes",
98+
Title: "Static routes:",
99+
Contents: output.Table{
100+
Columns: []output.TableColumn{
101+
{Key: "name", Header: "Name"},
102+
{Key: "route", Header: "Route", Colour: ui.DefaultAddressColours},
103+
{Key: "nexthop", Header: "Nexthop", Colour: ui.DefaultAddressColours},
104+
{Key: "type", Header: "Type"},
105+
},
106+
Rows: staticRouteRows,
107+
EmptyMessage: "No static routes defined for this router.",
108+
},
109+
},
87110
}
88111

89112
return output.MarshaledWithHumanOutput{

internal/commands/router/show_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,18 @@ func TestShowCommand(t *testing.T) {
6363
6464
Labels:
6565
66-
No labels defined for this resource.
66+
No labels defined for this router.
6767
6868
Networks:
6969
7070
UUID Name Type Zone
7171
────────────────────────────────────── ────────────── ───────── ─────────
7272
ce6a9934-c0c6-4d84-9ad4-0611f5b95e79 test-network utility uk-lon1
7373
74+
Static routes:
75+
76+
No static routes defined for this router.
77+
7478
`
7579
mService := smock.Service{}
7680
mService.On("GetRouters", mock.Anything).Return(&upcloud.Routers{Routers: []upcloud.Router{router}}, nil)

0 commit comments

Comments
 (0)