Skip to content

Commit 7fb466a

Browse files
committed
adapted network-area list command to align to expectations
1 parent f015fae commit 7fb466a

2 files changed

Lines changed: 24 additions & 19 deletions

File tree

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
@@ -167,6 +167,7 @@ func TestBuildRequest(t *testing.T) {
167167
func TestOutputResult(t *testing.T) {
168168
type args struct {
169169
outputFormat string
170+
orgLabel string
170171
networkAreas []iaas.NetworkArea
171172
}
172173
tests := []struct {
@@ -197,7 +198,7 @@ func TestOutputResult(t *testing.T) {
197198
params := testparams.NewTestParams()
198199
for _, tt := range tests {
199200
t.Run(tt.name, func(t *testing.T) {
200-
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.networkAreas); (err != nil) != tt.wantErr {
201+
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.orgLabel, tt.args.networkAreas); (err != nil) != tt.wantErr {
201202
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
202203
}
203204
})

0 commit comments

Comments
 (0)