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
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
Loading