Skip to content

Commit 8885e05

Browse files
committed
adapted server machine-types list command to align to expectations
1 parent 777630a commit 8885e05

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

internal/cmd/server/machine-type/list/list.go

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

83-
if resp.Items == nil || len(*resp.Items) == 0 {
84-
projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd)
85-
if err != nil {
86-
params.Printer.Debug(print.ErrorLevel, "get project name: %v", err)
87-
projectLabel = model.ProjectId
88-
}
89-
params.Printer.Info("No machine-types found for project %q\n", projectLabel)
90-
return nil
83+
projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd)
84+
if err != nil {
85+
params.Printer.Debug(print.ErrorLevel, "get project name: %v", err)
86+
projectLabel = model.ProjectId
9187
}
9288

9389
// limit output
9490
if model.Limit != nil && len(*resp.Items) > int(*model.Limit) {
9591
*resp.Items = (*resp.Items)[:*model.Limit]
9692
}
9793

98-
return outputResult(params.Printer, model.OutputFormat, *resp)
94+
return outputResult(params.Printer, model.OutputFormat, projectLabel, *resp)
9995
},
10096
}
10197

@@ -140,8 +136,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
140136
return req
141137
}
142138

143-
func outputResult(p *print.Printer, outputFormat string, machineTypes iaas.MachineTypeListResponse) error {
139+
func outputResult(p *print.Printer, outputFormat, projectLabel string, machineTypes iaas.MachineTypeListResponse) error {
144140
return p.OutputResult(outputFormat, machineTypes, func() error {
141+
if machineTypes.Items == nil || len(*machineTypes.Items) == 0 {
142+
p.Outputf("No machine-types found for project %q\n", projectLabel)
143+
return nil
144+
}
145145
table := tables.NewTable()
146146
table.SetTitle("Machine-Types")
147147
table.SetHeader("NAME", "VCPUS", "RAM (GB)", "DESCRIPTION", "EXTRA SPECS")

internal/cmd/server/machine-type/list/list_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ func TestBuildRequest(t *testing.T) {
179179
func TestOutputResult(t *testing.T) {
180180
type args struct {
181181
outputFormat string
182+
projectLabel string
182183
machineTypes iaas.MachineTypeListResponse
183184
}
184185
tests := []struct {
@@ -222,7 +223,7 @@ func TestOutputResult(t *testing.T) {
222223
params := testparams.NewTestParams()
223224
for _, tt := range tests {
224225
t.Run(tt.name, func(t *testing.T) {
225-
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.machineTypes); (err != nil) != tt.wantErr {
226+
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.projectLabel, tt.args.machineTypes); (err != nil) != tt.wantErr {
226227
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
227228
}
228229
})

0 commit comments

Comments
 (0)