Skip to content

Commit 6535939

Browse files
committed
adapted volumes list command to align to expectations
1 parent c8429b0 commit 6535939

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
@@ -176,6 +176,7 @@ func TestBuildRequest(t *testing.T) {
176176
func TestOutputResult(t *testing.T) {
177177
type args struct {
178178
outputFormat string
179+
projectLabel string
179180
volumes []iaas.Volume
180181
}
181182
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.volumes); (err != nil) != tt.wantErr {
204+
if err := outputResult(p, tt.args.outputFormat, tt.args.projectLabel, tt.args.volumes); (err != nil) != tt.wantErr {
204205
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
205206
}
206207
})

0 commit comments

Comments
 (0)