Skip to content

Commit 877acb7

Browse files
committed
adapted server commands list command to align to expectations
1 parent 47f322d commit 877acb7

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

internal/cmd/server/command/list/list.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,14 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7878
if err != nil {
7979
return fmt.Errorf("list server commands: %w", err)
8080
}
81-
if commands := resp.Items; commands == nil || len(*commands) == 0 {
82-
params.Printer.Info("No commands found for server %s\n", serverLabel)
83-
return nil
84-
}
85-
commands := *resp.Items
81+
82+
commands := resp.GetItems()
83+
8684
// Truncate output
8785
if model.Limit != nil && len(commands) > int(*model.Limit) {
8886
commands = commands[:*model.Limit]
8987
}
90-
return outputResult(params.Printer, model.OutputFormat, commands)
88+
return outputResult(params.Printer, model.OutputFormat, serverLabel, commands)
9189
},
9290
}
9391
configureFlags(cmd)
@@ -131,8 +129,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *runcommand.
131129
return req
132130
}
133131

134-
func outputResult(p *print.Printer, outputFormat string, commands []runcommand.Commands) error {
132+
func outputResult(p *print.Printer, outputFormat, serverLabel string, commands []runcommand.Commands) error {
135133
return p.OutputResult(outputFormat, commands, func() error {
134+
if len(commands) == 0 {
135+
p.Outputf("No commands found for server %s\n", serverLabel)
136+
return nil
137+
}
136138
table := tables.NewTable()
137139
table.SetHeader("ID", "TEMPLATE NAME", "TEMPLATE TITLE", "STATUS", "STARTED_AT", "FINISHED_AT")
138140
for i := range commands {

internal/cmd/server/command/list/list_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func TestBuildRequest(t *testing.T) {
157157
func TestOutputResult(t *testing.T) {
158158
type args struct {
159159
outputFormat string
160+
serverLabel string
160161
commands []runcommand.Commands
161162
}
162163
tests := []struct {
@@ -173,7 +174,7 @@ func TestOutputResult(t *testing.T) {
173174
params := testparams.NewTestParams()
174175
for _, tt := range tests {
175176
t.Run(tt.name, func(t *testing.T) {
176-
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.commands); (err != nil) != tt.wantErr {
177+
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.serverLabel, tt.args.commands); (err != nil) != tt.wantErr {
177178
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
178179
}
179180
})

0 commit comments

Comments
 (0)