Skip to content

Commit 48e9f80

Browse files
committed
adapted network area network ranges list command to align to expectations
1 parent 42eafa4 commit 48e9f80

2 files changed

Lines changed: 17 additions & 15 deletions

File tree

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,21 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7575
return fmt.Errorf("list network ranges: %w", err)
7676
}
7777

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

8987
// Truncate output
90-
items := *resp.Items
9188
if model.Limit != nil && len(items) > int(*model.Limit) {
9289
items = items[:*model.Limit]
9390
}
9491

95-
return outputResult(params.Printer, model.OutputFormat, items)
92+
return outputResult(params.Printer, model.OutputFormat, networkAreaLabel, items)
9693
},
9794
}
9895
configureFlags(cmd)
@@ -133,8 +130,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
133130
return apiClient.ListNetworkAreaRanges(ctx, *model.OrganizationId, *model.NetworkAreaId, model.Region)
134131
}
135132

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

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,9 @@ func TestBuildRequest(t *testing.T) {
183183

184184
func TestOutputResult(t *testing.T) {
185185
type args struct {
186-
outputFormat string
187-
networkRanges []iaas.NetworkRange
186+
outputFormat string
187+
networkAreaLabel string
188+
networkRanges []iaas.NetworkRange
188189
}
189190
tests := []struct {
190191
name string
@@ -214,7 +215,7 @@ func TestOutputResult(t *testing.T) {
214215
params := testparams.NewTestParams()
215216
for _, tt := range tests {
216217
t.Run(tt.name, func(t *testing.T) {
217-
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.networkRanges); (err != nil) != tt.wantErr {
218+
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.networkAreaLabel, tt.args.networkRanges); (err != nil) != tt.wantErr {
218219
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
219220
}
220221
})

0 commit comments

Comments
 (0)