Skip to content

Commit 1bba2f5

Browse files
chore(mongodbflex): move nil checks in outputResult into pretty print function, change version to value type
1 parent 6fa0bcd commit 1bba2f5

4 files changed

Lines changed: 13 additions & 14 deletions

File tree

internal/cmd/mongodbflex/backup/describe/describe.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *mongodbflex
119119
}
120120

121121
func outputResult(p *print.Printer, outputFormat, restoreStatus string, backup *mongodbflex.Backup) error {
122-
if backup == nil {
123-
return fmt.Errorf("API response is nil")
124-
}
125122
return p.OutputResult(outputFormat, backup, func() error {
123+
if backup == nil {
124+
return fmt.Errorf("API response is nil")
125+
}
126126
table := tables.NewTable()
127127
table.AddRow("ID", utils.PtrString(backup.Id))
128128
table.AddSeparator()

internal/cmd/mongodbflex/instance/create/create.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type inputModel struct {
5959
RAM *int32
6060
StorageClass *string
6161
StorageSize *int64
62-
Version *string
62+
Version string
6363
Type *string
6464
}
6565

@@ -107,12 +107,12 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
107107
}
108108

109109
// Fill in version, if needed
110-
if model.Version == nil {
110+
if model.Version == "" {
111111
version, err := mongodbflexUtils.GetLatestMongoDBVersion(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region)
112112
if err != nil {
113113
return fmt.Errorf("get latest MongoDB version: %w", err)
114114
}
115-
model.Version = &version
115+
model.Version = version
116116
}
117117

118118
// Call API
@@ -193,7 +193,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
193193
RAM: ram,
194194
StorageClass: utils.Ptr(flags.FlagWithDefaultToStringValue(p, cmd, storageClassFlag)),
195195
StorageSize: &storageSize,
196-
Version: flags.FlagToStringPointer(p, cmd, versionFlag),
196+
Version: flags.FlagToStringValue(p, cmd, versionFlag),
197197
Type: typeFlag.Ptr(),
198198
}
199199

@@ -259,7 +259,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient MongoDBFlexC
259259
Class: model.StorageClass,
260260
Size: model.StorageSize,
261261
},
262-
Version: *model.Version,
262+
Version: model.Version,
263263
Options: map[string]string{
264264
"type": *model.Type,
265265
},

internal/cmd/mongodbflex/instance/create/create_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
8383
FlavorId: utils.Ptr(testFlavorId),
8484
StorageClass: utils.Ptr("premium-perf4-mongodb"),
8585
StorageSize: utils.Ptr(int64(10)),
86-
Version: utils.Ptr("6.0"),
86+
Version: "6.0",
8787
Type: utils.Ptr("Replica"),
8888
}
8989
for _, mod := range mods {
@@ -216,7 +216,7 @@ func TestParseInput(t *testing.T) {
216216
}),
217217
isValid: true,
218218
expectedModel: fixtureInputModel(func(model *inputModel) {
219-
model.Version = nil
219+
model.Version = ""
220220
}),
221221
},
222222
{

internal/cmd/mongodbflex/instance/describe/describe.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,10 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *mongodbflex
9292
}
9393

9494
func outputResult(p *print.Printer, outputFormat string, instance *mongodbflex.Instance) error {
95-
if instance == nil {
96-
return fmt.Errorf("instance is nil")
97-
}
98-
9995
return p.OutputResult(outputFormat, instance, func() error {
96+
if instance == nil {
97+
return fmt.Errorf("instance is nil")
98+
}
10099
var instanceType string
101100
if instance.HasReplicas() {
102101
var err error

0 commit comments

Comments
 (0)