Skip to content

Commit a4efb91

Browse files
author
Yago Carlos Fernandez Gou
committed
address review comments: fix listing being empty
1 parent 8bc2e14 commit a4efb91

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

internal/cmd/intake/runner/list/list.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,21 @@ func NewListCmd(p *params.CmdParams) *cobra.Command {
6868
return fmt.Errorf("list Intake Runners: %w", err)
6969
}
7070
runners := resp.GetIntakeRunners()
71-
if len(runners) == 0 {
72-
projectLabel, err := projectname.GetProjectName(ctx, p.Printer, p.CliVersion, cmd)
73-
if err != nil {
74-
p.Printer.Debug(print.ErrorLevel, "get project name: %v", err)
75-
projectLabel = model.ProjectId
76-
}
77-
p.Printer.Outputf("No Intake Runners found for project %q\n", projectLabel)
78-
return nil
79-
}
8071

8172
// Truncate output
8273
if model.Limit != nil && len(runners) > int(*model.Limit) {
8374
runners = runners[:*model.Limit]
8475
}
8576

86-
return outputResult(p.Printer, model.OutputFormat, runners)
77+
projectLabel := model.ProjectId
78+
if len(runners) == 0 {
79+
projectLabel, err = projectname.GetProjectName(ctx, p.Printer, p.CliVersion, cmd)
80+
if err != nil {
81+
p.Printer.Debug(print.ErrorLevel, "get project name: %v", err)
82+
}
83+
}
84+
85+
return outputResult(p.Printer, model.OutputFormat, projectLabel, runners)
8786
},
8887
}
8988
configureFlags(cmd)
@@ -137,7 +136,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *intake.APIC
137136
}
138137

139138
// outputResult formats the API response and prints it to the console
140-
func outputResult(p *print.Printer, outputFormat string, runners []intake.IntakeRunnerResponse) error {
139+
func outputResult(p *print.Printer, outputFormat, projectLabel string, runners []intake.IntakeRunnerResponse) error {
141140
switch outputFormat {
142141
case print.JSONOutputFormat:
143142
details, err := json.MarshalIndent(runners, "", " ")
@@ -156,6 +155,11 @@ func outputResult(p *print.Printer, outputFormat string, runners []intake.Intake
156155
return nil
157156

158157
default:
158+
if len(runners) == 0 {
159+
p.Outputf("No intake runners found for project %q\n", projectLabel)
160+
return nil
161+
}
162+
159163
table := tables.NewTable()
160164

161165
table.SetHeader("ID", "NAME")

internal/cmd/intake/runner/list/list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func TestOutputResult(t *testing.T) {
220220
p.Cmd = NewListCmd(&params.CmdParams{Printer: p})
221221
for _, tt := range tests {
222222
t.Run(tt.name, func(t *testing.T) {
223-
if err := outputResult(p, tt.args.outputFormat, tt.args.runners); (err != nil) != tt.wantErr {
223+
if err := outputResult(p, tt.args.outputFormat, "dummy-projectlabel", tt.args.runners); (err != nil) != tt.wantErr {
224224
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
225225
}
226226
})

0 commit comments

Comments
 (0)