Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
386dc10
feat(server): add async output handling for server creation
s-inter Mar 4, 2026
e0ca2d7
feat(volume): add async output handling
s-inter Mar 9, 2026
9029102
feat(network-area): add async output handling
s-inter Mar 9, 2026
1f89580
feat(git): add async output handling for instance creation
s-inter Mar 9, 2026
b04519a
feat(mongodbflex): add async output handling in restore and clone com…
s-inter Mar 9, 2026
f0ba899
Merge remote-tracking branch 'origin/main' into feat/consistent-outpu…
s-inter Mar 9, 2026
3667ecd
feat(kms): add async output handling
s-inter Mar 10, 2026
4248524
feat(sfs): add async output handling
s-inter Mar 10, 2026
d02de70
Merge branch 'main' into feat/consistent-output-for-async
s-inter Mar 10, 2026
c6715b5
Merge remote-tracking branch 'origin/main' into feat/consistent-outpu…
s-inter Mar 16, 2026
ec0972e
fix(kms): remove hardcoded async in outputResult tests
s-inter Mar 16, 2026
1edb1e2
fix(sfs): remove hardcoded async in outputResult tests
s-inter Mar 16, 2026
6e7d725
refactor(kms): unify output handling for async operations
s-inter Mar 16, 2026
976271f
Merge branch 'main' into feat/consistent-output-for-async
s-inter Mar 20, 2026
1f45c26
Update internal/cmd/git/instance/create/create.go
s-inter Mar 20, 2026
6d22550
refactor(git): clean up outputResult function by passing only require…
s-inter Mar 20, 2026
c153566
refactor(git): fix tests & removed redundant checks
s-inter Mar 20, 2026
89bac06
fix(git): remove Id from inputModel
s-inter Mar 20, 2026
52fd2cc
Merge branch 'main' into feat/consistent-output-for-async
s-inter Mar 20, 2026
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/beta/sfs/resource-pool/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ The available performance class values can be obtained by running:
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 @@ -170,13 +170,17 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
return &model, nil
}

func outputResult(p *print.Printer, outputFormat, projectLabel string, resp *sfs.CreateResourcePoolResponse) error {
func outputResult(p *print.Printer, outputFormat string, async bool, projectLabel string, resp *sfs.CreateResourcePoolResponse) error {
return p.OutputResult(outputFormat, resp, func() error {
if resp == nil || resp.ResourcePool == nil {
p.Outputln("Resource pool response is empty")
return nil
}
p.Outputf("Created resource pool for project %q. Resource pool ID: %s\n", projectLabel, utils.PtrString(resp.ResourcePool.Id))
operationState := "Created"
if async {
operationState = "Triggered creation of"
}
p.Outputf("%s resource pool for project %q. Resource pool ID: %s\n", operationState, projectLabel, utils.PtrString(resp.ResourcePool.Id))
return nil
})
}
3 changes: 2 additions & 1 deletion internal/cmd/beta/sfs/resource-pool/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ func TestBuildRequest(t *testing.T) {
func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
async bool
projectLabel string
resp *sfs.CreateResourcePoolResponse
}
Expand Down Expand Up @@ -287,7 +288,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.resp); (err != nil) != tt.wantErr {
if err := outputResult(p, tt.args.outputFormat, tt.args.async, tt.args.projectLabel, tt.args.resp); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand Down
10 changes: 7 additions & 3 deletions internal/cmd/beta/sfs/resource-pool/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
s.Stop()
}

return outputResult(params.Printer, model.OutputFormat, resourcePoolName, resp)
return outputResult(params.Printer, model.OutputFormat, model.Async, resourcePoolName, resp)
},
}
return cmd
Expand Down Expand Up @@ -110,9 +110,13 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
return &model, nil
}

func outputResult(p *print.Printer, outputFormat, resourcePoolName string, response map[string]interface{}) error {
func outputResult(p *print.Printer, outputFormat string, async bool, resourcePoolName string, response map[string]interface{}) error {
return p.OutputResult(outputFormat, response, func() error {
p.Outputf("Deleted resource pool %q\n", resourcePoolName)
operationState := "Deleted"
if async {
operationState = "Triggered deletion of"
}
p.Outputf("%s resource pool %q\n", operationState, resourcePoolName)
return nil
})
}
3 changes: 2 additions & 1 deletion internal/cmd/beta/sfs/resource-pool/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func TestBuildRequest(t *testing.T) {
func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
async bool
resourcePoolName string
response map[string]interface{}
}
Expand All @@ -201,7 +202,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.resourcePoolName, tt.args.response); (err != nil) != tt.wantErr {
if err := outputResult(p, tt.args.outputFormat, tt.args.async, tt.args.resourcePoolName, tt.args.response); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand Down
10 changes: 7 additions & 3 deletions internal/cmd/beta/sfs/resource-pool/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ The available performance class values can be obtained by running:
s.Stop()
}

return outputResult(params.Printer, model.OutputFormat, resp)
return outputResult(params.Printer, model.OutputFormat, model.Async, resp)
},
}
configureFlags(cmd)
Expand Down Expand Up @@ -165,13 +165,17 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
return &model, nil
}

func outputResult(p *print.Printer, outputFormat string, resp *sfs.UpdateResourcePoolResponse) error {
func outputResult(p *print.Printer, outputFormat string, async bool, resp *sfs.UpdateResourcePoolResponse) error {
return p.OutputResult(outputFormat, resp, func() error {
if resp == nil || resp.ResourcePool == nil {
p.Outputln("Resource pool response is empty")
return nil
}
p.Outputf("Updated resource pool %s\n", utils.PtrString(resp.ResourcePool.Name))
operationState := "Updated"
if async {
operationState = "Triggered update of"
}
p.Outputf("%s resource pool %s\n", operationState, utils.PtrString(resp.ResourcePool.Name))
return nil
})
}
3 changes: 2 additions & 1 deletion internal/cmd/beta/sfs/resource-pool/update/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ func TestBuildRequest(t *testing.T) {
func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
async bool
resp *sfs.UpdateResourcePoolResponse
}
tests := []struct {
Expand Down Expand Up @@ -353,7 +354,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.resp); (err != nil) != tt.wantErr {
if err := outputResult(p, tt.args.outputFormat, tt.args.async, tt.args.resp); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand Down
24 changes: 12 additions & 12 deletions internal/cmd/git/instance/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/git/client"
"github.com/stackitcloud/stackit-cli/internal/pkg/spinner"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
"github.com/stackitcloud/stackit-sdk-go/services/git"
"github.com/stackitcloud/stackit-sdk-go/services/git/wait"
)
Expand All @@ -28,7 +27,6 @@ const (

type inputModel struct {
*globalflags.GlobalFlagModel
Id *string
Name string
Flavor string
Acl []string
Expand Down Expand Up @@ -80,20 +78,19 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
if err != nil {
return fmt.Errorf("create stackit git instance: %w", err)
}
model.Id = result.Id

// Wait for async operation, if async mode not enabled
if !model.Async {
s := spinner.New(params.Printer)
s.Start("Creating stackit git instance")
_, err = wait.CreateGitInstanceWaitHandler(ctx, apiClient, model.ProjectId, *model.Id).WaitWithContext(ctx)
_, err = wait.CreateGitInstanceWaitHandler(ctx, apiClient, model.ProjectId, *result.Id).WaitWithContext(ctx)
if err != nil {
return fmt.Errorf("wait for stackit git Instance creation: %w", err)
}
s.Stop()
}

return outputResult(params.Printer, model, result)
return outputResult(params.Printer, model.OutputFormat, model.Async, model.Name, result)
},
}

Expand Down Expand Up @@ -143,17 +140,20 @@ func createPayload(model *inputModel) git.CreateInstancePayload {
}
}

func outputResult(p *print.Printer, model *inputModel, resp *git.Instance) error {
if model == nil {
return fmt.Errorf("input model is nil")
func outputResult(p *print.Printer, outputFormat string, async bool, instanceName string, resp *git.Instance) error {
if resp == nil {
return fmt.Errorf("API resp is nil")
}
var outputFormat string
if model.GlobalFlagModel != nil {
outputFormat = model.OutputFormat
if resp.Id == nil {
return fmt.Errorf("API resp is missing instance id")
}

return p.OutputResult(outputFormat, resp, func() error {
p.Outputf("Created instance %q with id %s\n", model.Name, utils.PtrString(model.Id))
operationState := "Created"
if async {
operationState = "Triggered creation of"
}
p.Outputf("%s instance %q with id %s\n", operationState, instanceName, *resp.Id)
return nil
})
}
32 changes: 18 additions & 14 deletions internal/cmd/git/instance/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,39 +175,43 @@ func TestBuildRequest(t *testing.T) {

func TestOutputResult(t *testing.T) {
type args struct {
model *inputModel
resp *git.Instance
outputFormat string
async bool
instanceName string
resp *git.Instance
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "nil",
name: "nil response",
args: args{
model: nil,
resp: nil,
outputFormat: "",
async: false,
instanceName: "",
resp: nil,
},
wantErr: true,
},
{
name: "empty input",
args: args{
model: &inputModel{},
resp: &git.Instance{},
outputFormat: "",
async: false,
instanceName: "",
resp: &git.Instance{Id: utils.Ptr(uuid.NewString())},
},
wantErr: false,
},
{
name: "output json",
args: args{
model: &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
OutputFormat: print.JSONOutputFormat,
},
},
resp: nil,
outputFormat: print.JSONOutputFormat,
async: true,
instanceName: testName,
resp: &git.Instance{Id: utils.Ptr(uuid.NewString())},
},
wantErr: false,
},
Expand All @@ -216,7 +220,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.model, tt.args.resp); (err != nil) != tt.wantErr {
if err := outputResult(p, tt.args.outputFormat, tt.args.async, tt.args.instanceName, tt.args.resp); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand Down
23 changes: 3 additions & 20 deletions internal/cmd/kms/key/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package create

import (
"context"
"encoding/json"
"fmt"

"github.com/stackitcloud/stackit-cli/internal/pkg/types"

"github.com/goccy/go-yaml"
"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
Expand Down Expand Up @@ -159,29 +157,14 @@ func outputResult(p *print.Printer, model *inputModel, resp *kms.Key) error {
return fmt.Errorf("response is nil")
}

switch model.OutputFormat {
case print.JSONOutputFormat:
details, err := json.MarshalIndent(resp, "", " ")
if err != nil {
return fmt.Errorf("marshal KMS key: %w", err)
}
p.Outputln(string(details))

case print.YAMLOutputFormat:
details, err := yaml.MarshalWithOptions(resp, yaml.IndentSequence(true), yaml.UseJSONMarshaler())
if err != nil {
return fmt.Errorf("marshal KMS key: %w", err)
}
p.Outputln(string(details))

default:
return p.OutputResult(model.OutputFormat, resp, func() error {
operationState := "Created"
if model.Async {
operationState = "Triggered creation of"
}
p.Outputf("%s the KMS key %q. Key ID: %s\n", operationState, utils.PtrString(resp.DisplayName), utils.PtrString(resp.Id))
}
return nil
return nil
})
}

func configureFlags(cmd *cobra.Command) {
Expand Down
22 changes: 3 additions & 19 deletions internal/cmd/kms/key/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package delete

import (
"context"
"encoding/json"
"fmt"

"github.com/stackitcloud/stackit-cli/internal/pkg/types"

"github.com/goccy/go-yaml"
"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
Expand Down Expand Up @@ -127,22 +125,8 @@ func outputResult(p *print.Printer, outputFormat string, resp *kms.Key) error {
return fmt.Errorf("response is nil")
}

switch outputFormat {
case print.JSONOutputFormat:
details, err := json.MarshalIndent(resp, "", " ")
if err != nil {
return fmt.Errorf("marshal output to JSON: %w", err)
}
p.Outputln(string(details))
case print.YAMLOutputFormat:
details, err := yaml.MarshalWithOptions(resp, yaml.IndentSequence(true), yaml.UseJSONMarshaler())
if err != nil {
return fmt.Errorf("marshal output to YAML: %w", err)
}
p.Outputln(string(details))

default:
return p.OutputResult(outputFormat, resp, func() error {
p.Outputf("Deletion of KMS key %s scheduled successfully for the deletion date: %s\n", utils.PtrString(resp.DisplayName), utils.PtrString(resp.DeletionDate))
}
return nil
return nil
})
}
24 changes: 3 additions & 21 deletions internal/cmd/kms/key/importKey/importKey.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package importKey
import (
"context"
"encoding/base64"
"encoding/json"
"fmt"

"github.com/stackitcloud/stackit-cli/internal/pkg/types"

"github.com/goccy/go-yaml"
"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
Expand Down Expand Up @@ -148,26 +146,10 @@ func outputResult(p *print.Printer, outputFormat, keyRingName, keyName string, r
return fmt.Errorf("response is nil")
}

switch outputFormat {
case print.JSONOutputFormat:
details, err := json.MarshalIndent(resp, "", " ")
if err != nil {
return fmt.Errorf("marshal KMS key: %w", err)
}
p.Outputln(string(details))

case print.YAMLOutputFormat:
details, err := yaml.MarshalWithOptions(resp, yaml.IndentSequence(true), yaml.UseJSONMarshaler())
if err != nil {
return fmt.Errorf("marshal KMS key: %w", err)
}
p.Outputln(string(details))

default:
return p.OutputResult(outputFormat, resp, func() error {
p.Outputf("Imported a new version for the key %q inside the key ring %q\n", keyName, keyRingName)
}

return nil
return nil
})
}

func configureFlags(cmd *cobra.Command) {
Expand Down
Loading
Loading