Skip to content

Commit 75cddf2

Browse files
committed
review changes 3
1 parent 49d4669 commit 75cddf2

33 files changed

+978
-803
lines changed

docs/stackit_routing-table_create.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ stackit routing-table create [flags]
1919
Create a routing-table with name `rt` and description `some description`
2020
stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --description "some description"
2121
22-
Create a routing-table with name `rt` with system_routes disabled
22+
Create a routing-table with name `rt` with system routes disabled
2323
stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --non-system-routes
2424
25-
Create a routing-table with name `rt` with dynamic_routes disabled
25+
Create a routing-table with name `rt` with dynamic routes disabled
2626
stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --non-dynamic-routes
2727
```
2828

docs/stackit_routing-table_delete.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Deletes a routing-table
77
Deletes a routing-table
88

99
```
10-
stackit routing-table delete ROUTING_TABLE_ARG [flags]
10+
stackit routing-table delete ROUTING_TABLE [flags]
1111
```
1212

1313
### Examples

docs/stackit_routing-table_describe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Describes a routing-table
77
Describes a routing-table
88

99
```
10-
stackit routing-table describe ROUTING_TABLE_ID_ARG [flags]
10+
stackit routing-table describe ROUTING_TABLE_ID [flags]
1111
```
1212

1313
### Examples

docs/stackit_routing-table_route_describe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Describes a route within a routing-table
77
Describes a route within a routing-table
88

99
```
10-
stackit routing-table route describe ROUTE_ID_ARG [flags]
10+
stackit routing-table route describe ROUTE_ID [flags]
1111
```
1212

1313
### Examples

docs/stackit_routing-table_route_update.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Updates a route in a routing-table
77
Updates a route in a routing-table.
88

99
```
10-
stackit routing-table route update ROUTE_ID_ARG [flags]
10+
stackit routing-table route update ROUTE_ID [flags]
1111
```
1212

1313
### Examples

docs/stackit_routing-table_update.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Updates a routing-table
77
Updates a routing-table.
88

99
```
10-
stackit routing-table update ROUTE_TABLE_ID_ARG [flags]
10+
stackit routing-table update ROUTE_TABLE_ID [flags]
1111
```
1212

1313
### Examples
@@ -22,7 +22,7 @@ stackit routing-table update ROUTE_TABLE_ID_ARG [flags]
2222
Updates the description of a routing-table with ID "xxx" in organization with ID "yyy" and network-area with ID "zzz"
2323
$ stackit routing-table update xxx --description foo --organization-id yyy --network-area-id zzz
2424
25-
Disables the dynamic_routes of a routing-table with ID "xxx" in organization with ID "yyy" and network-area with ID "zzz"
25+
Disables the dynamic routes of a routing-table with ID "xxx" in organization with ID "yyy" and network-area with ID "zzz"
2626
$ stackit routing-table update xxx --organization-id yyy --network-area-id zzz --non-dynamic-routes
2727
```
2828

internal/cmd/network/create/create.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,11 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
298298
}
299299

300300
payload := iaas.CreateNetworkPayload{
301-
Name: model.Name,
302-
Labels: utils.ConvertStringMapToInterfaceMap(model.Labels),
303-
Routed: utils.Ptr(!model.NonRouted),
304-
Ipv4: ipv4Network,
305-
Ipv6: ipv6Network,
301+
Name: model.Name,
302+
Labels: utils.ConvertStringMapToInterfaceMap(model.Labels),
303+
Routed: utils.Ptr(!model.NonRouted),
304+
Ipv4: ipv4Network,
305+
Ipv6: ipv6Network,
306306
RoutingTableId: model.RoutingTableID,
307307
}
308308

internal/cmd/network/describe/describe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func outputResult(p *print.Printer, outputFormat string, network *iaas.Network)
152152
table.AddSeparator()
153153

154154
if network.RoutingTableId != nil {
155-
table.AddRow("ROUTING-TABLE ID", utils.PtrString(network.RoutingTableId))
155+
table.AddRow("ROUTING TABLE ID", utils.PtrString(network.RoutingTableId))
156156
table.AddSeparator()
157157
}
158158

internal/cmd/routingtable/create/create.go

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ import (
44
"context"
55
"fmt"
66
"strings"
7-
"time"
87

98
"github.com/spf13/cobra"
10-
"github.com/stackitcloud/stackit-cli/internal/cmd/params"
119
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1210
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
1311
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
1412
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1513
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1614
"github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client"
1715
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
16+
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
1817
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1918
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
2019
)
@@ -40,7 +39,7 @@ type inputModel struct {
4039
OrganizationId string
4140
}
4241

43-
func NewCmd(params *params.CmdParams) *cobra.Command {
42+
func NewCmd(params *types.CmdParams) *cobra.Command {
4443
cmd := &cobra.Command{
4544
Use: "create",
4645
Short: "Creates a routing-table",
@@ -56,11 +55,11 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
5655
`stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --description "some description"`,
5756
),
5857
examples.NewExample(
59-
"Create a routing-table with name `rt` with system_routes disabled",
58+
"Create a routing-table with name `rt` with system routes disabled",
6059
`stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --non-system-routes`,
6160
),
6261
examples.NewExample(
63-
"Create a routing-table with name `rt` with dynamic_routes disabled",
62+
"Create a routing-table with name `rt` with dynamic routes disabled",
6463
`stackit routing-table create --organization-id xxx --network-area-id yyy --name "rt" --non-dynamic-routes`,
6564
),
6665
),
@@ -132,15 +131,8 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
132131
}
133132

134133
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) (iaas.ApiAddRoutingTableToAreaRequest, error) {
135-
systemRoutes := true
136-
if model.NonSystemRoutes {
137-
systemRoutes = false
138-
}
139-
140-
dynamicRoutes := true
141-
if model.NonDynamicRoutes {
142-
dynamicRoutes = false
143-
}
134+
systemRoutes := !model.NonSystemRoutes
135+
dynamicRoutes := !model.NonDynamicRoutes
144136

145137
payload := iaas.AddRoutingTableToAreaPayload{
146138
Description: model.Description,
@@ -175,28 +167,18 @@ func outputResult(p *print.Printer, outputFormat string, routingTable *iaas.Rout
175167
}
176168
}
177169

178-
createdAt := ""
179-
if routingTable.CreatedAt != nil {
180-
createdAt = routingTable.CreatedAt.Format(time.RFC3339)
181-
}
182-
183-
updatedAt := ""
184-
if routingTable.UpdatedAt != nil {
185-
updatedAt = routingTable.UpdatedAt.Format(time.RFC3339)
186-
}
187-
188170
table := tables.NewTable()
189-
table.SetHeader("ID", "NAME", "DESCRIPTION", "CREATED_AT", "UPDATED_AT", "DEFAULT", "LABELS", "SYSTEM_ROUTES", "DYNAMIC_ROUTES")
171+
table.SetHeader("ID", "NAME", "DESCRIPTION", "DEFAULT", "LABELS", "SYSTEM ROUTES", "DYNAMIC ROUTES", "CREATED AT", "UPDATED AT")
190172
table.AddRow(
191173
utils.PtrString(routingTable.Id),
192174
utils.PtrString(routingTable.Name),
193175
utils.PtrString(routingTable.Description),
194-
createdAt,
195-
updatedAt,
196176
utils.PtrString(routingTable.Default),
197177
strings.Join(labels, "\n"),
198178
utils.PtrString(routingTable.SystemRoutes),
199179
utils.PtrString(routingTable.DynamicRoutes),
180+
utils.ConvertTimePToDateTimeString(routingTable.CreatedAt),
181+
utils.ConvertTimePToDateTimeString(routingTable.UpdatedAt),
200182
)
201183

202184
err := table.Display(p)

internal/cmd/routingtable/create/create_test.go

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99
"github.com/google/go-cmp/cmp"
1010
"github.com/google/go-cmp/cmp/cmpopts"
1111
"github.com/google/uuid"
12-
"github.com/stackitcloud/stackit-cli/internal/cmd/params"
1312
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
14-
pprint "github.com/stackitcloud/stackit-cli/internal/pkg/print"
13+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1514
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
15+
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
1616
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1717
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1818
)
@@ -29,8 +29,12 @@ var testNetworkAreaId = uuid.NewString()
2929

3030
const testRoutingTableName = "test"
3131
const testRoutingTableDescription = "test"
32-
const systemRoutesDisabled = true
33-
const dynamicRoutesDisabled = true
32+
33+
// Defaults: “non-system” / “non-dynamic” routes disabled = false
34+
// => system + dynamic routes enabled by default.
35+
const systemRoutesDisabled = false
36+
const dynamicRoutesDisabled = false
37+
3438
const testLabelSelectorFlag = "key1=value1,key2=value2"
3539

3640
var testLabels = &map[string]string{
@@ -85,15 +89,9 @@ func fixtureRequest(mods ...func(request *iaas.ApiAddRoutingTableToAreaRequest))
8589
}
8690

8791
func fixturePayload(mods ...func(payload *iaas.AddRoutingTableToAreaPayload)) iaas.AddRoutingTableToAreaPayload {
88-
systemRoutes := true
89-
if dynamicRoutesDisabled {
90-
systemRoutes = false
91-
}
92-
93-
dynamicRoutes := true
94-
if systemRoutesDisabled {
95-
dynamicRoutes = false
96-
}
92+
// Actual booleans are the negation of the corresponding disabled flags.
93+
systemRoutes := !systemRoutesDisabled
94+
dynamicRoutes := !dynamicRoutesDisabled
9795

9896
payload := iaas.AddRoutingTableToAreaPayload{
9997
Description: utils.Ptr(testRoutingTableDescription),
@@ -124,7 +122,7 @@ func TestParseInput(t *testing.T) {
124122
expectedModel: fixtureInputModel(),
125123
},
126124
{
127-
description: "dynamic_routes disabled",
125+
description: "dynamic routes disabled",
128126
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
129127
flagValues[nonDynamicRoutesFlag] = "true"
130128
}),
@@ -134,7 +132,7 @@ func TestParseInput(t *testing.T) {
134132
}),
135133
},
136134
{
137-
description: "system_routes disabled",
135+
description: "system routes disabled",
138136
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
139137
flagValues[nonSystemRoutesFlag] = "true"
140138
}),
@@ -243,9 +241,11 @@ func TestBuildRequest(t *testing.T) {
243241
model.Labels = nil
244242
}),
245243
expectedRequest: fixtureRequest(func(request *iaas.ApiAddRoutingTableToAreaRequest) {
246-
*request = (*request).AddRoutingTableToAreaPayload(fixturePayload(func(payload *iaas.AddRoutingTableToAreaPayload) {
247-
payload.Labels = nil
248-
}))
244+
*request = (*request).AddRoutingTableToAreaPayload(
245+
fixturePayload(func(payload *iaas.AddRoutingTableToAreaPayload) {
246+
payload.Labels = nil
247+
}),
248+
)
249249
}),
250250
},
251251
{
@@ -254,9 +254,11 @@ func TestBuildRequest(t *testing.T) {
254254
model.NonSystemRoutes = true
255255
}),
256256
expectedRequest: fixtureRequest(func(request *iaas.ApiAddRoutingTableToAreaRequest) {
257-
*request = (*request).AddRoutingTableToAreaPayload(fixturePayload(func(payload *iaas.AddRoutingTableToAreaPayload) {
258-
payload.SystemRoutes = utils.Ptr(false)
259-
}))
257+
*request = (*request).AddRoutingTableToAreaPayload(
258+
fixturePayload(func(payload *iaas.AddRoutingTableToAreaPayload) {
259+
payload.SystemRoutes = utils.Ptr(false)
260+
}),
261+
)
260262
}),
261263
},
262264
{
@@ -265,9 +267,11 @@ func TestBuildRequest(t *testing.T) {
265267
model.NonDynamicRoutes = true
266268
}),
267269
expectedRequest: fixtureRequest(func(request *iaas.ApiAddRoutingTableToAreaRequest) {
268-
*request = (*request).AddRoutingTableToAreaPayload(fixturePayload(func(payload *iaas.AddRoutingTableToAreaPayload) {
269-
payload.DynamicRoutes = utils.Ptr(false)
270-
}))
270+
*request = (*request).AddRoutingTableToAreaPayload(
271+
fixturePayload(func(payload *iaas.AddRoutingTableToAreaPayload) {
272+
payload.DynamicRoutes = utils.Ptr(false)
273+
}),
274+
)
271275
}),
272276
},
273277
}
@@ -314,32 +318,32 @@ func TestOutputResult(t *testing.T) {
314318
},
315319
{
316320
name: "empty routing-table",
317-
outputFormat: "",
321+
outputFormat: print.PrettyOutputFormat,
318322
routingTable: &iaas.RoutingTable{},
319323
wantErr: true,
320324
},
321325
{
322-
name: "table output routing-table",
323-
outputFormat: "",
326+
name: "pretty output routing-table",
327+
outputFormat: print.PrettyOutputFormat,
324328
routingTable: &dummyRoutingTable,
325329
wantErr: false,
326330
},
327331
{
328332
name: "json output routing-table",
329-
outputFormat: pprint.JSONOutputFormat,
333+
outputFormat: print.JSONOutputFormat,
330334
routingTable: &dummyRoutingTable,
331335
wantErr: false,
332336
},
333337
{
334338
name: "yaml output routing-table",
335-
outputFormat: pprint.YAMLOutputFormat,
339+
outputFormat: print.YAMLOutputFormat,
336340
routingTable: &dummyRoutingTable,
337341
wantErr: false,
338342
},
339343
}
340344

341-
p := pprint.NewPrinter()
342-
p.Cmd = NewCmd(&params.CmdParams{Printer: p})
345+
p := print.NewPrinter()
346+
p.Cmd = NewCmd(&types.CmdParams{Printer: p})
343347
for _, tt := range tests {
344348
t.Run(tt.name, func(t *testing.T) {
345349
if err := outputResult(p, tt.outputFormat, tt.routingTable); (err != nil) != tt.wantErr {

0 commit comments

Comments
 (0)