Skip to content

Commit 7e58730

Browse files
committed
fix: implement review feedback
1 parent e738d95 commit 7e58730

File tree

22 files changed

+56
-95
lines changed

22 files changed

+56
-95
lines changed

internal/cmd/beta/key-pair/describe/describe.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ func NewCmd(p *print.Printer) *cobra.Command {
7171
return fmt.Errorf("read key pair: %w", err)
7272
}
7373

74-
return outputResult(p, model.OutputFormat, model.PublicKey, resp)
74+
if keypair := resp; keypair != nil {
75+
return outputResult(p, model.OutputFormat, model.PublicKey, *keypair)
76+
}
77+
p.Outputln("No keypair found.")
78+
return nil
7579
},
7680
}
7781
configureFlags(cmd)
@@ -109,11 +113,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
109113
return apiClient.GetKeyPair(ctx, model.KeyPairName)
110114
}
111115

112-
func outputResult(p *print.Printer, outputFormat string, showOnlyPublicKey bool, keyPair *iaas.Keypair) error {
113-
if keyPair == nil {
114-
p.Outputln("No keypair found.")
115-
return nil
116-
}
116+
func outputResult(p *print.Printer, outputFormat string, showOnlyPublicKey bool, keyPair iaas.Keypair) error {
117117
switch outputFormat {
118118
case print.JSONOutputFormat:
119119
details, err := json.MarshalIndent(keyPair, "", " ")

internal/cmd/beta/key-pair/describe/describe_test.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,28 +191,19 @@ func Test_outputResult(t *testing.T) {
191191
type args struct {
192192
outputFormat string
193193
showOnlyPublicKey bool
194-
keyPair *iaas.Keypair
194+
keyPair iaas.Keypair
195195
}
196196
tests := []struct {
197197
name string
198198
args args
199199
wantErr bool
200200
}{
201-
{
202-
name: "empty",
203-
args: args{
204-
outputFormat: "",
205-
showOnlyPublicKey: false,
206-
keyPair: nil,
207-
},
208-
wantErr: false,
209-
},
210201
{
211202
name: "base",
212203
args: args{
213204
outputFormat: "",
214205
showOnlyPublicKey: false,
215-
keyPair: &iaas.Keypair{},
206+
keyPair: iaas.Keypair{},
216207
},
217208
wantErr: false,
218209
},

internal/cmd/beta/network/list/list.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"strings"
87

98
"github.com/goccy/go-yaml"
109
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
@@ -165,10 +164,7 @@ func outputResult(p *print.Printer, outputFormat string, networks []iaas.Network
165164
if network.Routed != nil {
166165
routed = *network.Routed
167166
}
168-
prefixes := ""
169-
if network.Prefixes != nil && len(*network.Prefixes) > 0 {
170-
prefixes = strings.Join(*network.Prefixes, ", ")
171-
}
167+
prefixes := utils.JoinStringPtr(network.Prefixes, ", ")
172168

173169
table.AddRow(
174170
utils.PtrString(network.NetworkId),

internal/cmd/beta/public-ip/list/list.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,7 @@ func outputResult(p *print.Printer, outputFormat string, publicIps []iaas.Public
168168
table.SetHeader("ID", "IP ADDRESS", "USED BY")
169169

170170
for _, publicIp := range publicIps {
171-
networkInterfaceId := ""
172-
if publicIp.NetworkInterface != nil {
173-
networkInterfaceId = *publicIp.GetNetworkInterface()
174-
}
171+
networkInterfaceId := utils.PtrStringDefault(publicIp.GetNetworkInterface(), "")
175172
table.AddRow(
176173
utils.PtrString(publicIp.Id),
177174
utils.PtrString(publicIp.Ip),

internal/cmd/beta/security-group/rule/list/list.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,7 @@ func outputResult(p *print.Printer, outputFormat string, securityGroupRules []ia
170170
table.SetHeader("ID", "ETHER TYPE", "DIRECTION", "PROTOCOL", "REMOTE SECURITY GROUP ID")
171171

172172
for _, securityGroupRule := range securityGroupRules {
173-
etherType := ""
174-
if securityGroupRule.Ethertype != nil {
175-
etherType = *securityGroupRule.Ethertype
176-
}
173+
etherType := utils.PtrStringDefault(securityGroupRule.Ethertype, "")
177174

178175
protocolName := ""
179176
if securityGroupRule.Protocol != nil {

internal/cmd/beta/server/backup/describe/describe.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,7 @@ func outputResult(p *print.Printer, outputFormat string, backup *serverbackup.Ba
142142
table.AddRow("EXPIRES AT", utils.PtrString(backup.ExpireAt))
143143
table.AddSeparator()
144144

145-
lastRestored := ""
146-
if backup.LastRestoredAt != nil {
147-
lastRestored = *backup.LastRestoredAt
148-
}
145+
lastRestored := utils.PtrStringDefault(backup.LastRestoredAt, "")
149146
table.AddRow("LAST RESTORED AT", lastRestored)
150147
table.AddSeparator()
151148
table.AddRow("VOLUME BACKUPS", len(*backup.VolumeBackups))

internal/cmd/beta/server/backup/list/list.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,7 @@ func outputResult(p *print.Printer, outputFormat string, backups []serverbackup.
149149
for i := range backups {
150150
s := backups[i]
151151

152-
lastRestored := ""
153-
if s.LastRestoredAt != nil {
154-
lastRestored = *s.LastRestoredAt
155-
}
152+
lastRestored := utils.PtrStringDefault(s.LastRestoredAt, "")
156153
table.AddRow(
157154
utils.PtrString(s.Id),
158155
utils.PtrString(s.Name),

internal/cmd/beta/server/backup/schedule/describe/describe.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"strings"
87

98
"github.com/goccy/go-yaml"
109
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
@@ -144,11 +143,7 @@ func outputResult(p *print.Printer, outputFormat string, schedule *serverbackup.
144143
table.AddRow("BACKUP RETENTION DAYS", *schedule.BackupProperties.RetentionPeriod)
145144
table.AddSeparator()
146145
ids := schedule.BackupProperties.VolumeIds
147-
if ids == nil || len(*ids) == 0 {
148-
table.AddRow("BACKUP VOLUME IDS", "")
149-
} else {
150-
table.AddRow("BACKUP VOLUME IDS", strings.Join(*ids, "\n"))
151-
}
146+
table.AddRow("BACKUP VOLUME IDS", utils.JoinStringPtr(ids, "\n"))
152147
}
153148
err := table.Display(p)
154149
if err != nil {

internal/cmd/beta/server/backup/schedule/list/list.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"strings"
87

98
"github.com/goccy/go-yaml"
109
"github.com/spf13/cobra"
@@ -157,9 +156,7 @@ func outputResult(p *print.Printer, outputFormat string, schedules []serverbacku
157156
backupName = utils.PtrString(s.BackupProperties.Name)
158157
retentionPeriod = utils.PtrString(s.BackupProperties.RetentionPeriod)
159158

160-
if s.BackupProperties.VolumeIds != nil && len(*s.BackupProperties.VolumeIds) != 0 {
161-
ids = strings.Join(*s.BackupProperties.VolumeIds, ",")
162-
}
159+
ids = utils.JoinStringPtr(s.BackupProperties.VolumeIds, ",")
163160
}
164161
table.AddRow(
165162
utils.PtrString(s.Id),

internal/cmd/beta/server/command/template/list/list.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"strings"
87

98
"github.com/goccy/go-yaml"
109
"github.com/spf13/cobra"
@@ -145,7 +144,7 @@ func outputResult(p *print.Printer, outputFormat string, templates []runcommand.
145144

146145
var osType string
147146
if s.OsType != nil && len(*s.OsType) > 0 {
148-
osType = strings.Join(*s.OsType, ",")
147+
osType = utils.JoinStringPtr(s.OsType, ",")
149148
}
150149

151150
table.AddRow(

0 commit comments

Comments
 (0)