Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0aea155
fix returning empty server array in case the response does not return…
j1n-o9r Apr 13, 2026
3746b40
adapted outputResult signature to comply to linter
j1n-o9r Apr 13, 2026
cc50e9b
switched to getter for retrieving the items
j1n-o9r Apr 13, 2026
a4adb80
adapted printing behavior to align with expected behavior
j1n-o9r Apr 13, 2026
4542beb
change printing to defined output instead of stderr
j1n-o9r Apr 13, 2026
7ca2dce
adapted network list command to align to expectations
j1n-o9r Apr 13, 2026
1a67bad
remove unnecessary normalization of nil value in response items after…
j1n-o9r Apr 13, 2026
90dee7f
adapted network-area list command to align to expectations
j1n-o9r Apr 13, 2026
a31e39f
removed redundant check
j1n-o9r Apr 13, 2026
dca821f
adapted affinity list command to align to expectations
j1n-o9r Apr 15, 2026
fb181fb
adapted image list command to align to expectations
j1n-o9r Apr 15, 2026
111062a
adapted key pair list command to align to expectations
j1n-o9r Apr 15, 2026
815287a
fixed debug print in key pair list command
j1n-o9r Apr 15, 2026
d19379d
move project label retrieval
j1n-o9r Apr 15, 2026
0bc8501
adapted public ip list command to align to expectations
j1n-o9r Apr 15, 2026
1666e15
adapted security group list command to align to expectations
j1n-o9r Apr 15, 2026
c8429b0
added missing --limit flag for list security groups command
j1n-o9r Apr 15, 2026
6535939
adapted volumes list command to align to expectations
j1n-o9r Apr 15, 2026
d5b1c14
adapted volume snapshots list command to align to expectations
j1n-o9r Apr 15, 2026
9a2972b
adapted volume performance class list command to align to expectations
j1n-o9r Apr 15, 2026
f3a2379
adapted volume backups list command to align to expectations
j1n-o9r Apr 15, 2026
84fb653
fixed order of params
j1n-o9r Apr 15, 2026
5c17195
adapted network area network ranges list command to align to expectat…
j1n-o9r Apr 15, 2026
434f580
adapted network area routes list command to align to expectations
j1n-o9r Apr 15, 2026
cc5c7e9
adapted security group rules list command to align to expectations
j1n-o9r Apr 15, 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
29 changes: 16 additions & 13 deletions internal/cmd/affinity-groups/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/projectname"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client"
)

Expand Down Expand Up @@ -63,16 +64,19 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
if err != nil {
return fmt.Errorf("list affinity groups: %w", err)
}
items := result.GetItems()

if items := result.Items; items != nil {
if model.Limit != nil && len(*items) > int(*model.Limit) {
*items = (*items)[:*model.Limit]
}
return outputResult(params.Printer, *model, *items)
projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd)
if err != nil {
params.Printer.Debug(print.ErrorLevel, "get project name: %v", err)
projectLabel = model.ProjectId
}

params.Printer.Outputln("No affinity groups found")
return nil
// Truncate Output
if model.Limit != nil && len(items) > int(*model.Limit) {
items = items[:*model.Limit]
}
return outputResult(params.Printer, model.OutputFormat, projectLabel, items)
},
}
configureFlags(cmd)
Expand Down Expand Up @@ -110,13 +114,12 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
return &model, nil
}

func outputResult(p *print.Printer, model inputModel, items []iaas.AffinityGroup) error {
var outputFormat string
if model.GlobalFlagModel != nil {
outputFormat = model.OutputFormat
}

func outputResult(p *print.Printer, outputFormat, projectLabel string, items []iaas.AffinityGroup) error {
return p.OutputResult(outputFormat, items, func() error {
if len(items) == 0 {
p.Outputf("No affinity groups found for project %q\n", projectLabel)
return nil
}
table := tables.NewTable()
table.SetHeader("ID", "NAME", "POLICY")
for _, item := range items {
Expand Down
13 changes: 8 additions & 5 deletions internal/cmd/affinity-groups/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,24 +142,27 @@ func TestBuildRequest(t *testing.T) {
}

func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
projectLabel string
instances []iaas.AffinityGroup
}
tests := []struct {
description string
model inputModel
response []iaas.AffinityGroup
args args
isValid bool
}{
{
description: "empty",
model: inputModel{},
response: []iaas.AffinityGroup{},
args: args{},
isValid: true,
},
}
p := print.NewPrinter()
p.Cmd = NewCmd(&types.CmdParams{Printer: p})
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
err := outputResult(p, tt.model, tt.response)
err := outputResult(p, tt.args.outputFormat, tt.args.projectLabel, tt.args.instances)
if err != nil {
if !tt.isValid {
return
Expand Down
23 changes: 12 additions & 11 deletions internal/cmd/image/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,18 @@ func NewCmd(params *types.CmdParams) *cobra.Command {

// Call API
request := buildRequest(ctx, model, apiClient)

response, err := request.Execute()
if err != nil {
return fmt.Errorf("list images: %w", err)
}
items := response.GetItems()

if items := response.GetItems(); len(items) == 0 {
params.Printer.Info("No images found for project %q", projectLabel)
} else {
if model.Limit != nil && len(items) > int(*model.Limit) {
items = (items)[:*model.Limit]
}
if err := outputResult(params.Printer, model.OutputFormat, items); err != nil {
return fmt.Errorf("output images: %w", err)
}
// Truncate output
if model.Limit != nil && len(items) > int(*model.Limit) {
items = (items)[:*model.Limit]
}
if err := outputResult(params.Printer, model.OutputFormat, projectLabel, items); err != nil {
return fmt.Errorf("output images: %w", err)
}

return nil
Expand Down Expand Up @@ -149,8 +146,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
return request
}

func outputResult(p *print.Printer, outputFormat string, items []iaas.Image) error {
func outputResult(p *print.Printer, outputFormat, projectLabel string, items []iaas.Image) error {
return p.OutputResult(outputFormat, items, func() error {
if len(items) == 0 {
p.Outputf("No images found for project %q\n", projectLabel)
return nil
}
table := tables.NewTable()
table.SetHeader("ID", "NAME", "OS", "ARCHITECTURE", "DISTRIBUTION", "VERSION", "SCOPE", "OWNER", "LABELS")
for i := range items {
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/image/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func TestBuildRequest(t *testing.T) {
func Test_outputResult(t *testing.T) {
type args struct {
outputFormat string
projectLabel string
items []iaas.Image
}
tests := []struct {
Expand Down Expand Up @@ -217,7 +218,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.items); (err != nil) != tt.wantErr {
if err := outputResult(p, tt.args.outputFormat, tt.args.projectLabel, tt.args.items); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand Down
21 changes: 15 additions & 6 deletions internal/cmd/key-pair/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"strings"

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

"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
Expand Down Expand Up @@ -77,17 +78,20 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
return fmt.Errorf("list key pairs: %w", err)
}

if resp.Items == nil || len(*resp.Items) == 0 {
params.Printer.Info("No key pairs found\n")
return nil
items := resp.GetItems()

projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd)
if err != nil {
params.Printer.Debug(print.ErrorLevel, "get project name: %v", err)
projectLabel = model.ProjectId
}

items := *resp.Items
// Truncate output
if model.Limit != nil && len(items) > int(*model.Limit) {
items = items[:*model.Limit]
}

return outputResult(params.Printer, model.OutputFormat, items)
return outputResult(params.Printer, model.OutputFormat, projectLabel, items)
},
}
configureFlags(cmd)
Expand Down Expand Up @@ -128,8 +132,13 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
return req
}

func outputResult(p *print.Printer, outputFormat string, keyPairs []iaas.Keypair) error {
func outputResult(p *print.Printer, outputFormat, projectLabel string, keyPairs []iaas.Keypair) error {
return p.OutputResult(outputFormat, keyPairs, func() error {
if len(keyPairs) == 0 {
p.Outputf("No key pairs found for project %q\n", projectLabel)
return nil
}

table := tables.NewTable()
table.SetHeader("KEY PAIR NAME", "LABELS", "FINGERPRINT", "CREATED AT", "UPDATED AT")

Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/key-pair/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func TestBuildRequest(t *testing.T) {
func Test_outputResult(t *testing.T) {
type args struct {
outputFormat string
projectLabel string
keyPairs []iaas.Keypair
}
tests := []struct {
Expand All @@ -179,7 +180,7 @@ func Test_outputResult(t *testing.T) {
p := print.NewPrinter()
p.Cmd = NewCmd(&types.CmdParams{Printer: p})

if err := outputResult(p, tt.args.outputFormat, tt.args.keyPairs); (err != nil) != tt.wantErr {
if err := outputResult(p, tt.args.outputFormat, tt.args.projectLabel, tt.args.keyPairs); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand Down
40 changes: 22 additions & 18 deletions internal/cmd/network-area/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,30 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
return fmt.Errorf("list network areas: %w", err)
}

if resp.Items == nil || len(*resp.Items) == 0 {
var orgLabel string
rmApiClient, err := rmClient.ConfigureClient(params.Printer, params.CliVersion)
if err == nil {
orgLabel, err = rmUtils.GetOrganizationName(ctx, rmApiClient, *model.OrganizationId)
if err != nil {
params.Printer.Debug(print.ErrorLevel, "get organization name: %v", err)
orgLabel = *model.OrganizationId
} else if orgLabel == "" {
orgLabel = *model.OrganizationId
}
} else {
params.Printer.Debug(print.ErrorLevel, "configure resource manager client: %v", err)
items := resp.GetItems()

var orgLabel string
rmApiClient, err := rmClient.ConfigureClient(params.Printer, params.CliVersion)
if err == nil {
orgLabel, err = rmUtils.GetOrganizationName(ctx, rmApiClient, *model.OrganizationId)
if err != nil {
params.Printer.Debug(print.ErrorLevel, "get organization name: %v", err)
orgLabel = *model.OrganizationId
}
params.Printer.Info("No STACKIT Network Areas found for organization %q\n", orgLabel)
return nil
} else {
params.Printer.Debug(print.ErrorLevel, "configure resource manager client: %v", err)
}

if orgLabel == "" {
orgLabel = *model.OrganizationId
}

// Truncate output
items := *resp.Items
if model.Limit != nil && len(items) > int(*model.Limit) {
items = items[:*model.Limit]
}

return outputResult(params.Printer, model.OutputFormat, items)
return outputResult(params.Printer, model.OutputFormat, orgLabel, items)
},
}
configureFlags(cmd)
Expand Down Expand Up @@ -149,8 +148,13 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
return req
}

func outputResult(p *print.Printer, outputFormat string, networkAreas []iaas.NetworkArea) error {
func outputResult(p *print.Printer, outputFormat, orgLabel string, networkAreas []iaas.NetworkArea) error {
return p.OutputResult(outputFormat, networkAreas, func() error {
if len(networkAreas) == 0 {
p.Outputf("No STACKIT Network Areas found for organization %q\n", orgLabel)
return nil
}

table := tables.NewTable()
table.SetHeader("ID", "Name", "# Attached Projects")

Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/network-area/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func TestBuildRequest(t *testing.T) {
func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
orgLabel string
networkAreas []iaas.NetworkArea
}
tests := []struct {
Expand Down Expand Up @@ -200,7 +201,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.networkAreas); (err != nil) != tt.wantErr {
if err := outputResult(p, tt.args.outputFormat, tt.args.orgLabel, tt.args.networkAreas); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand Down
25 changes: 13 additions & 12 deletions internal/cmd/network-area/network-range/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,21 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
return fmt.Errorf("list network ranges: %w", err)
}

if resp.Items == nil || len(*resp.Items) == 0 {
var networkAreaLabel string
networkAreaLabel, err = iaasUtils.GetNetworkAreaName(ctx, apiClient, *model.OrganizationId, *model.NetworkAreaId)
if err != nil {
params.Printer.Debug(print.ErrorLevel, "get organization name: %v", err)
networkAreaLabel = *model.NetworkAreaId
}
params.Printer.Info("No network ranges found for SNA %q\n", networkAreaLabel)
return nil
items := resp.GetItems()

var networkAreaLabel string
networkAreaLabel, err = iaasUtils.GetNetworkAreaName(ctx, apiClient, *model.OrganizationId, *model.NetworkAreaId)
if err != nil {
params.Printer.Debug(print.ErrorLevel, "get organization name: %v", err)
networkAreaLabel = *model.NetworkAreaId
}

// Truncate output
items := *resp.Items
if model.Limit != nil && len(items) > int(*model.Limit) {
items = items[:*model.Limit]
}

return outputResult(params.Printer, model.OutputFormat, items)
return outputResult(params.Printer, model.OutputFormat, networkAreaLabel, items)
},
}
configureFlags(cmd)
Expand Down Expand Up @@ -133,8 +130,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
return apiClient.ListNetworkAreaRanges(ctx, *model.OrganizationId, *model.NetworkAreaId, model.Region)
}

func outputResult(p *print.Printer, outputFormat string, networkRanges []iaas.NetworkRange) error {
func outputResult(p *print.Printer, outputFormat, networkAreaLabel string, networkRanges []iaas.NetworkRange) error {
return p.OutputResult(outputFormat, networkRanges, func() error {
if len(networkRanges) == 0 {
p.Outputf("No network ranges found for SNA %q\n", networkAreaLabel)
return nil
}
table := tables.NewTable()
table.SetHeader("ID", "Network Range")

Expand Down
7 changes: 4 additions & 3 deletions internal/cmd/network-area/network-range/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ func TestBuildRequest(t *testing.T) {

func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
networkRanges []iaas.NetworkRange
outputFormat string
networkAreaLabel string
networkRanges []iaas.NetworkRange
}
tests := []struct {
name string
Expand Down Expand Up @@ -217,7 +218,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.networkRanges); (err != nil) != tt.wantErr {
if err := outputResult(p, tt.args.outputFormat, tt.args.networkAreaLabel, tt.args.networkRanges); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand Down
Loading