Skip to content

Commit 2d82ab3

Browse files
committed
review changes
1 parent 565f907 commit 2d82ab3

File tree

4 files changed

+16
-43
lines changed

4 files changed

+16
-43
lines changed

docs/stackit_routing-table_update.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ stackit routing-table update ROUTING_TABLE_ID [flags]
2323
$ stackit routing-table update xxx --description foo --organization-id yyy --network-area-id zzz
2424
2525
Disables the dynamic routes of a routing-table with ID "xxx" in organization with ID "yyy" and network-area with ID "zzz"
26-
$ stackit routing-table update xxx --organization-id yyy --network-area-id zzz --disable-dynamic-routes
26+
$ stackit routing-table update xxx --organization-id yyy --network-area-id zzz --dynamic-routes=false
2727
2828
Disables the system routes of a routing-table with ID "xxx" in organization with ID "yyy" and network-area with ID "zzz"
29-
$ stackit routing-table update xxx --organization-id yyy --network-area-id zzz --disable-system-routes
29+
$ stackit routing-table update xxx --organization-id yyy --network-area-id zzz --system-routes=false
3030
```
3131

3232
### Options

internal/cmd/routingtable/create/create.go

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package create
33
import (
44
"context"
55
"fmt"
6-
"strings"
76

87
"github.com/spf13/cobra"
98
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
@@ -12,7 +11,6 @@ import (
1211
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1312
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1413
"github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client"
15-
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
1614
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
1715
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1816
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
@@ -147,40 +145,16 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
147145
}
148146

149147
func outputResult(p *print.Printer, outputFormat string, routingTable *iaas.RoutingTable) error {
148+
if routingTable == nil {
149+
return fmt.Errorf("routing-table is nil")
150+
}
151+
152+
if routingTable.Id == nil {
153+
return fmt.Errorf("create routing-table id is empty")
154+
}
155+
150156
return p.OutputResult(outputFormat, routingTable, func() error {
151-
if routingTable == nil {
152-
return fmt.Errorf("create routing-table response is empty")
153-
}
154-
155-
if routingTable.Id == nil {
156-
return fmt.Errorf("create routing-table id is empty")
157-
}
158-
159-
var labels []string
160-
if routingTable.Labels != nil && len(*routingTable.Labels) > 0 {
161-
for key, value := range *routingTable.Labels {
162-
labels = append(labels, fmt.Sprintf("%s: %s", key, value))
163-
}
164-
}
165-
166-
table := tables.NewTable()
167-
table.SetHeader("ID", "NAME", "DESCRIPTION", "DEFAULT", "LABELS", "SYSTEM ROUTES", "DYNAMIC ROUTES", "CREATED AT", "UPDATED AT")
168-
table.AddRow(
169-
utils.PtrString(routingTable.Id),
170-
utils.PtrString(routingTable.Name),
171-
utils.PtrString(routingTable.Description),
172-
utils.PtrString(routingTable.Default),
173-
strings.Join(labels, "\n"),
174-
utils.PtrString(routingTable.SystemRoutes),
175-
utils.PtrString(routingTable.DynamicRoutes),
176-
utils.ConvertTimePToDateTimeString(routingTable.CreatedAt),
177-
utils.ConvertTimePToDateTimeString(routingTable.UpdatedAt),
178-
)
179-
180-
err := table.Display(p)
181-
if err != nil {
182-
return fmt.Errorf("render table: %w", err)
183-
}
157+
p.Outputf("Created Routing-Table with ID %q\n", utils.PtrString(routingTable.Id))
184158
return nil
185159
})
186160
}

internal/cmd/routingtable/update/update.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
6060
),
6161
examples.NewExample(
6262
`Disables the dynamic routes of a routing-table with ID "xxx" in organization with ID "yyy" and network-area with ID "zzz"`,
63-
"$ stackit routing-table update xxx --organization-id yyy --network-area-id zzz --disable-dynamic-routes",
63+
"$ stackit routing-table update xxx --organization-id yyy --network-area-id zzz --dynamic-routes=false",
6464
),
6565
examples.NewExample(
6666
`Disables the system routes of a routing-table with ID "xxx" in organization with ID "yyy" and network-area with ID "zzz"`,
67-
"$ stackit routing-table update xxx --organization-id yyy --network-area-id zzz --disable-system-routes",
67+
"$ stackit routing-table update xxx --organization-id yyy --network-area-id zzz --system-routes=false",
6868
),
6969
),
7070
RunE: func(cmd *cobra.Command, args []string) error {

internal/pkg/services/routingtable/utils/utils.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package utils
22

33
import (
44
"fmt"
5-
"strings"
65
"time"
76

87
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
@@ -47,11 +46,11 @@ func ExtractRouteDetails(route iaas.Route) RouteDetails {
4746
}
4847

4948
if route.Labels != nil && len(*route.Labels) > 0 {
50-
var labels []string
49+
stringMap := make(map[string]string)
5150
for key, value := range *route.Labels {
52-
labels = append(labels, fmt.Sprintf("%s: %s", key, value))
51+
stringMap[key] = fmt.Sprintf("%v", value)
5352
}
54-
routeDetails.Labels = strings.Join(labels, "\n")
53+
routeDetails.Labels = utils.JoinStringMap(stringMap, ": ", "\n")
5554
}
5655

5756
if route.CreatedAt != nil {

0 commit comments

Comments
 (0)