From 386dc1053ae459767c0e71c8df5d0191df744324 Mon Sep 17 00:00:00 2001 From: "Inter, Sven" Date: Wed, 4 Mar 2026 15:09:48 +0100 Subject: [PATCH] feat(server): add async output handling for server creation --- internal/cmd/server/create/create.go | 10 +++++++--- internal/cmd/server/create/create_test.go | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/cmd/server/create/create.go b/internal/cmd/server/create/create.go index a93efcbf7..ab5253af0 100644 --- a/internal/cmd/server/create/create.go +++ b/internal/cmd/server/create/create.go @@ -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) @@ -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 }) } diff --git a/internal/cmd/server/create/create_test.go b/internal/cmd/server/create/create_test.go index 521b80922..7ab029013 100644 --- a/internal/cmd/server/create/create_test.go +++ b/internal/cmd/server/create/create_test.go @@ -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 } @@ -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) } })