Skip to content

Commit 90dee7f

Browse files
committed
adapted network-area list command to align to expectations
1 parent 1a67bad commit 90dee7f

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

internal/cmd/network-area/list/list.go

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,30 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
8080
return fmt.Errorf("list network areas: %w", err)
8181
}
8282

83-
if resp.Items == nil || len(*resp.Items) == 0 {
84-
var orgLabel string
85-
rmApiClient, err := rmClient.ConfigureClient(params.Printer, params.CliVersion)
86-
if err == nil {
87-
orgLabel, err = rmUtils.GetOrganizationName(ctx, rmApiClient, *model.OrganizationId)
88-
if err != nil {
89-
params.Printer.Debug(print.ErrorLevel, "get organization name: %v", err)
90-
orgLabel = *model.OrganizationId
91-
} else if orgLabel == "" {
92-
orgLabel = *model.OrganizationId
93-
}
94-
} else {
95-
params.Printer.Debug(print.ErrorLevel, "configure resource manager client: %v", err)
83+
items := resp.GetItems()
84+
85+
var orgLabel string
86+
rmApiClient, err := rmClient.ConfigureClient(params.Printer, params.CliVersion)
87+
if err == nil {
88+
orgLabel, err = rmUtils.GetOrganizationName(ctx, rmApiClient, *model.OrganizationId)
89+
if err != nil {
90+
params.Printer.Debug(print.ErrorLevel, "get organization name: %v", err)
91+
orgLabel = *model.OrganizationId
9692
}
97-
params.Printer.Info("No STACKIT Network Areas found for organization %q\n", orgLabel)
98-
return nil
93+
} else {
94+
params.Printer.Debug(print.ErrorLevel, "configure resource manager client: %v", err)
95+
}
96+
97+
if orgLabel == "" {
98+
orgLabel = *model.OrganizationId
9999
}
100100

101101
// Truncate output
102-
items := *resp.Items
103102
if model.Limit != nil && len(items) > int(*model.Limit) {
104103
items = items[:*model.Limit]
105104
}
106105

107-
return outputResult(params.Printer, model.OutputFormat, items)
106+
return outputResult(params.Printer, orgLabel, model.OutputFormat, items)
108107
},
109108
}
110109
configureFlags(cmd)
@@ -149,8 +148,13 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
149148
return req
150149
}
151150

152-
func outputResult(p *print.Printer, outputFormat string, networkAreas []iaas.NetworkArea) error {
151+
func outputResult(p *print.Printer, orgLabel, outputFormat string, networkAreas []iaas.NetworkArea) error {
153152
return p.OutputResult(outputFormat, networkAreas, func() error {
153+
if len(networkAreas) == 0 {
154+
p.Outputf("No STACKIT Network Areas found for organization %q\n", orgLabel)
155+
return nil
156+
}
157+
154158
table := tables.NewTable()
155159
table.SetHeader("ID", "Name", "# Attached Projects")
156160

internal/cmd/network-area/list/list_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ func TestBuildRequest(t *testing.T) {
169169
func TestOutputResult(t *testing.T) {
170170
type args struct {
171171
outputFormat string
172+
orgLabel string
172173
networkAreas []iaas.NetworkArea
173174
}
174175
tests := []struct {
@@ -200,7 +201,7 @@ func TestOutputResult(t *testing.T) {
200201
p.Cmd = NewCmd(&types.CmdParams{Printer: p})
201202
for _, tt := range tests {
202203
t.Run(tt.name, func(t *testing.T) {
203-
if err := outputResult(p, tt.args.outputFormat, tt.args.networkAreas); (err != nil) != tt.wantErr {
204+
if err := outputResult(p, tt.args.outputFormat, tt.args.orgLabel, tt.args.networkAreas); (err != nil) != tt.wantErr {
204205
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
205206
}
206207
})

0 commit comments

Comments
 (0)