Skip to content

Commit f8d2829

Browse files
committed
adapted volumes list command to align to expectations
1 parent b3afc4b commit f8d2829

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

internal/cmd/volume/list/list.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,20 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7676
return fmt.Errorf("list volumes: %w", err)
7777
}
7878

79-
if resp.Items == nil || len(*resp.Items) == 0 {
80-
projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd)
81-
if err != nil {
82-
params.Printer.Debug(print.ErrorLevel, "get project name: %v", err)
83-
projectLabel = model.ProjectId
84-
}
85-
params.Printer.Info("No volumes found for project %q\n", projectLabel)
86-
return nil
79+
items := resp.GetItems()
80+
81+
projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd)
82+
if err != nil {
83+
params.Printer.Debug(print.ErrorLevel, "get project name: %v", err)
84+
projectLabel = model.ProjectId
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, projectLabel, items)
9693
},
9794
}
9895
configureFlags(cmd)
@@ -137,8 +134,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
137134
return req
138135
}
139136

140-
func outputResult(p *print.Printer, outputFormat string, volumes []iaas.Volume) error {
137+
func outputResult(p *print.Printer, outputFormat, projectLabel string, volumes []iaas.Volume) error {
141138
return p.OutputResult(outputFormat, volumes, func() error {
139+
if len(volumes) == 0 {
140+
p.Outputf("No volumes found for project %q\n", projectLabel)
141+
return nil
142+
}
142143
table := tables.NewTable()
143144
table.SetHeader("ID", "Name", "Status", "Server", "Availability Zone", "Size (GB)")
144145

internal/cmd/volume/list/list_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ func TestBuildRequest(t *testing.T) {
174174
func TestOutputResult(t *testing.T) {
175175
type args struct {
176176
outputFormat string
177+
projectLabel string
177178
volumes []iaas.Volume
178179
}
179180
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.volumes); (err != nil) != tt.wantErr {
201+
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.projectLabel, tt.args.volumes); (err != nil) != tt.wantErr {
201202
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
202203
}
203204
})

0 commit comments

Comments
 (0)