Skip to content

Commit b8ffc82

Browse files
committed
adapted server commands list command to align to expectations
1 parent cc5c7e9 commit b8ffc82

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
@@ -159,6 +159,7 @@ func TestBuildRequest(t *testing.T) {
159159
func TestOutputResult(t *testing.T) {
160160
type args struct {
161161
outputFormat string
162+
serverLabel string
162163
commands []runcommand.Commands
163164
}
164165
tests := []struct {
@@ -176,7 +177,7 @@ func TestOutputResult(t *testing.T) {
176177
p.Cmd = NewCmd(&types.CmdParams{Printer: p})
177178
for _, tt := range tests {
178179
t.Run(tt.name, func(t *testing.T) {
179-
if err := outputResult(p, tt.args.outputFormat, tt.args.commands); (err != nil) != tt.wantErr {
180+
if err := outputResult(p, tt.args.outputFormat, tt.args.serverLabel, tt.args.commands); (err != nil) != tt.wantErr {
180181
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
181182
}
182183
})

0 commit comments

Comments
 (0)