Skip to content

Commit bb29706

Browse files
committed
implement review feedback
1 parent f3cc252 commit bb29706

File tree

2 files changed

+16
-29
lines changed

2 files changed

+16
-29
lines changed

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
4343
),
4444
RunE: func(cmd *cobra.Command, args []string) error {
4545
ctx := context.Background()
46-
model, err := parseInput(p, cmd, args)
47-
if err != nil {
48-
return err
49-
}
46+
model := parseInput(p, cmd, args)
5047

5148
// Configure API client
5249
apiClient, err := client.ConfigureClient(p)
@@ -63,13 +60,16 @@ func NewCmd(p *print.Printer) *cobra.Command {
6360
}
6461

6562
// Call API
66-
req := buildRequest(ctx, model, apiClient)
63+
req := buildRequest(ctx, &model, apiClient)
6764
resp, err := req.Execute()
6865
if err != nil {
6966
return fmt.Errorf("update key pair: %w", err)
7067
}
68+
if resp == nil {
69+
return fmt.Errorf("response is nil")
70+
}
7171

72-
return outputResult(p, model, resp)
72+
return outputResult(p, model, *resp)
7373
},
7474
}
7575
configureFlags(cmd)
@@ -100,7 +100,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
100100
return req.UpdateKeyPairPayload(payload)
101101
}
102102

103-
func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
103+
func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) inputModel {
104104
keyPairName := inputArgs[0]
105105
globalFlags := globalflags.Parse(p, cmd)
106106

@@ -119,17 +119,10 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
119119
}
120120
}
121121

122-
return &model, nil
122+
return model
123123
}
124124

125-
func outputResult(p *print.Printer, model *inputModel, keyPair *iaas.Keypair) error {
126-
if model == nil {
127-
return fmt.Errorf("model is nil")
128-
}
129-
if keyPair == nil {
130-
return fmt.Errorf("keyPair is nil")
131-
}
132-
125+
func outputResult(p *print.Printer, model inputModel, keyPair iaas.Keypair) error {
133126
var outputFormat string
134127
if model.GlobalFlagModel != nil {
135128
outputFormat = model.GlobalFlagModel.OutputFormat

internal/cmd/beta/key-pair/update/update_test.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,12 @@ func TestParseInput(t *testing.T) {
141141
t.Fatalf("error validating args: %v", err)
142142
}
143143

144-
model, err := parseInput(p, cmd, tt.argValues)
145-
if err != nil {
146-
if !tt.isValid {
147-
return
148-
}
149-
t.Fatalf("error parsing flags: %v", err)
150-
}
144+
model := parseInput(p, cmd, tt.argValues)
151145

152146
if !tt.isValid {
153147
t.Fatalf("did not fail on invalid input")
154148
}
155-
diff := cmp.Diff(model, tt.expectedModel)
149+
diff := cmp.Diff(&model, tt.expectedModel)
156150
if diff != "" {
157151
t.Fatalf("Data does not match: %s", diff)
158152
}
@@ -191,8 +185,8 @@ func TestBuildRequest(t *testing.T) {
191185

192186
func Test_outputResult(t *testing.T) {
193187
type args struct {
194-
model *inputModel
195-
keyPair *iaas.Keypair
188+
model inputModel
189+
keyPair iaas.Keypair
196190
}
197191
tests := []struct {
198192
name string
@@ -202,13 +196,13 @@ func Test_outputResult(t *testing.T) {
202196
{
203197
name: "empty",
204198
args: args{},
205-
wantErr: true,
199+
wantErr: false,
206200
},
207201
{
208202
name: "base",
209203
args: args{
210-
model: &inputModel{},
211-
keyPair: &iaas.Keypair{},
204+
model: inputModel{},
205+
keyPair: iaas.Keypair{},
212206
},
213207
wantErr: false,
214208
},

0 commit comments

Comments
 (0)