Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
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
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
23 changes: 3 additions & 20 deletions internal/cmd/kms/key/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package list

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 @@ -106,22 +104,7 @@ func outputResult(p *print.Printer, outputFormat, projectId, keyRingId string, r

keys := *resp.Keys

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

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

default:
return p.OutputResult(outputFormat, keys, func() error {
if len(keys) == 0 {
p.Outputf("No keys found for project %q under the key ring %q\n", projectId, keyRingId)
return nil
Expand All @@ -144,6 +127,6 @@ func outputResult(p *print.Printer, outputFormat, projectId, keyRingId string, r
if err != nil {
return fmt.Errorf("render table: %w", err)
}
}
return nil
return nil
})
}
22 changes: 3 additions & 19 deletions internal/cmd/kms/key/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package restore

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 @@ -126,22 +124,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("Successfully restored KMS key %q\n", utils.PtrString(resp.DisplayName))
}
return nil
return nil
})
}
Loading
Loading