Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions internal/cmd/server/command/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,14 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
if err != nil {
return fmt.Errorf("list server commands: %w", err)
}
if commands := resp.Items; commands == nil || len(*commands) == 0 {
params.Printer.Info("No commands found for server %s\n", serverLabel)
return nil
}
commands := *resp.Items

commands := resp.GetItems()

// Truncate output
if model.Limit != nil && len(commands) > int(*model.Limit) {
commands = commands[:*model.Limit]
}
return outputResult(params.Printer, model.OutputFormat, commands)
return outputResult(params.Printer, model.OutputFormat, serverLabel, commands)
},
}
configureFlags(cmd)
Expand Down Expand Up @@ -131,8 +129,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *runcommand.
return req
}

func outputResult(p *print.Printer, outputFormat string, commands []runcommand.Commands) error {
func outputResult(p *print.Printer, outputFormat, serverLabel string, commands []runcommand.Commands) error {
return p.OutputResult(outputFormat, commands, func() error {
if len(commands) == 0 {
p.Outputf("No commands found for server %s\n", serverLabel)
return nil
}
table := tables.NewTable()
table.SetHeader("ID", "TEMPLATE NAME", "TEMPLATE TITLE", "STATUS", "STARTED_AT", "FINISHED_AT")
for i := range commands {
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/server/command/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func TestBuildRequest(t *testing.T) {
func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
serverLabel string
commands []runcommand.Commands
}
tests := []struct {
Expand All @@ -173,7 +174,7 @@ func TestOutputResult(t *testing.T) {
params := testparams.NewTestParams()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.commands); (err != nil) != tt.wantErr {
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.serverLabel, tt.args.commands); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand Down
11 changes: 6 additions & 5 deletions internal/cmd/server/command/template/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,8 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
if err != nil {
return fmt.Errorf("list server command templates: %w", err)
}
if templates := resp.Items; templates == nil || len(*templates) == 0 {
params.Printer.Info("No commands templates found\n")
return nil
}
templates := *resp.Items

templates := resp.GetItems()

// Truncate output
if model.Limit != nil && len(templates) > int(*model.Limit) {
Expand Down Expand Up @@ -113,6 +110,10 @@ func buildRequest(ctx context.Context, _ *inputModel, apiClient *runcommand.APIC

func outputResult(p *print.Printer, outputFormat string, templates []runcommand.CommandTemplate) error {
return p.OutputResult(outputFormat, templates, func() error {
if len(templates) == 0 {
p.Outputf("No commands templates found\n")
return nil
}
table := tables.NewTable()
table.SetHeader("NAME", "OS TYPE", "TITLE")
for i := range templates {
Expand Down