Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion internal/cmd/git/instance/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,18 @@ func outputResult(p *print.Printer, model *inputModel, resp *git.Instance) error
}

return p.OutputResult(outputFormat, resp, func() error {
p.Outputf("Created instance %q with id %s\n", model.Name, utils.PtrString(model.Id))
if resp == nil {
return nil
}
operationState := "Created"
if model.Async {
operationState = "Triggered creation of"
}
id := utils.PtrString(model.Id)
if resp.Id != nil {
id = *resp.Id
}
p.Outputf("%s instance %q with id %s\n", operationState, model.Name, id)
return nil
})
}
2 changes: 1 addition & 1 deletion internal/cmd/git/instance/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func TestOutputResult(t *testing.T) {
{
name: "empty input",
args: args{
model: &inputModel{},
model: fixtureInputModel(),
resp: &git.Instance{},
},
wantErr: false,
Expand Down
12 changes: 10 additions & 2 deletions internal/cmd/mongodbflex/backup/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
s.Stop()
}

params.Printer.Outputf("Restored instance %q with backup %q\n", model.InstanceId, model.BackupId)
operationState := "Restored"
if model.Async {
operationState = "Triggered restore of"
}
params.Printer.Outputf("%s instance %q with backup %q\n", operationState, model.InstanceId, model.BackupId)
return nil
}

Expand All @@ -129,7 +133,11 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
s.Stop()
}

params.Printer.Outputf("Cloned instance %q from backup with timestamp %q\n", model.InstanceId, model.Timestamp)
operationState := "Cloned"
if model.Async {
operationState = "Triggered clone of"
}
params.Printer.Outputf("%s instance %q from backup with timestamp %q\n", operationState, model.InstanceId, model.Timestamp)
return nil
},
}
Expand Down
10 changes: 7 additions & 3 deletions internal/cmd/network-area/region/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
s.Stop()
}

return outputResult(params.Printer, model.OutputFormat, model.Region, networkAreaLabel, *resp)
return outputResult(params.Printer, model.OutputFormat, model.Async, model.Region, networkAreaLabel, *resp)
},
}
configureFlags(cmd)
Expand Down Expand Up @@ -186,9 +186,13 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
return req.CreateNetworkAreaRegionPayload(payload)
}

func outputResult(p *print.Printer, outputFormat, region, networkAreaLabel string, regionalArea iaas.RegionalArea) error {
func outputResult(p *print.Printer, outputFormat string, async bool, region, networkAreaLabel string, regionalArea iaas.RegionalArea) error {
return p.OutputResult(outputFormat, regionalArea, func() error {
p.Outputf("Create region configuration for SNA %q.\nRegion: %s\n", networkAreaLabel, region)
operationState := "Created"
if async {
operationState = "Triggered creation of"
}
p.Outputf("%s region configuration for SNA %q.\nRegion: %s\n", operationState, networkAreaLabel, region)
return nil
})
}
3 changes: 2 additions & 1 deletion internal/cmd/network-area/region/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func TestBuildRequest(t *testing.T) {
func Test_outputResult(t *testing.T) {
type args struct {
outputFormat string
async bool
region string
networkAreaLabel string
regionalArea iaas.RegionalArea
Expand Down Expand Up @@ -300,7 +301,7 @@ func Test_outputResult(t *testing.T) {
p.Cmd = NewCmd(&types.CmdParams{Printer: p})
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := outputResult(p, tt.args.outputFormat, tt.args.region, tt.args.networkAreaLabel, tt.args.regionalArea); (err != nil) != tt.wantErr {
if err := outputResult(p, tt.args.outputFormat, tt.args.async, tt.args.region, tt.args.networkAreaLabel, tt.args.regionalArea); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand Down
10 changes: 7 additions & 3 deletions internal/cmd/server/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
s.Stop()
}

return outputResult(params.Printer, model.OutputFormat, projectLabel, resp)
return outputResult(params.Printer, model.OutputFormat, model.Async, projectLabel, resp)
},
}
configureFlags(cmd)
Expand Down Expand Up @@ -322,12 +322,16 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
return req.CreateServerPayload(payload)
}

func outputResult(p *print.Printer, outputFormat, projectLabel string, server *iaas.Server) error {
func outputResult(p *print.Printer, outputFormat string, async bool, projectLabel string, server *iaas.Server) error {
if server == nil {
return fmt.Errorf("server response is empty")
}
return p.OutputResult(outputFormat, server, func() error {
p.Outputf("Created server for project %q.\nServer ID: %s\n", projectLabel, utils.PtrString(server.Id))
operationState := "Created"
if async {
operationState = "Triggered creation of"
}
p.Outputf("%s server for project %q.\nServer ID: %s\n", operationState, projectLabel, utils.PtrString(server.Id))
return nil
})
}
3 changes: 2 additions & 1 deletion internal/cmd/server/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ func TestBuildRequest(t *testing.T) {
func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
async bool
projectLabel string
server *iaas.Server
}
Expand All @@ -407,7 +408,7 @@ func TestOutputResult(t *testing.T) {
p.Cmd = NewCmd(&types.CmdParams{Printer: p})
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := outputResult(p, tt.args.outputFormat, tt.args.projectLabel, tt.args.server); (err != nil) != tt.wantErr {
if err := outputResult(p, tt.args.outputFormat, tt.args.async, tt.args.projectLabel, tt.args.server); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand Down
6 changes: 5 additions & 1 deletion internal/cmd/volume/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel string, volu
return fmt.Errorf("volume response is empty")
}
return p.OutputResult(model.OutputFormat, volume, func() error {
p.Outputf("Created volume for project %q.\nVolume ID: %s\n", projectLabel, utils.PtrString(volume.Id))
operationState := "Created"
if model.Async {
operationState = "Triggered creation of"
}
p.Outputf("%s volume for project %q.\nVolume ID: %s\n", operationState, projectLabel, utils.PtrString(volume.Id))
return nil
})
}
Loading