Skip to content

Commit 7bf4df1

Browse files
j1n-o9rrubenhoenle
authored andcommitted
adapted server backup schedules list command to align to expectations
1 parent 726b7f1 commit 7bf4df1

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

internal/cmd/server/backup/schedule/list/list.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,13 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7878
if err != nil {
7979
return fmt.Errorf("list server backup schedules: %w", err)
8080
}
81-
schedules := *resp.Items
82-
if len(schedules) == 0 {
83-
params.Printer.Info("No backup schedules found for server %s\n", serverLabel)
84-
return nil
85-
}
81+
schedules := resp.GetItems()
8682

8783
// Truncate output
8884
if model.Limit != nil && len(schedules) > int(*model.Limit) {
8985
schedules = schedules[:*model.Limit]
9086
}
91-
return outputResult(params.Printer, model.OutputFormat, schedules)
87+
return outputResult(params.Printer, model.OutputFormat, serverLabel, schedules)
9288
},
9389
}
9490
configureFlags(cmd)
@@ -132,8 +128,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *serverbacku
132128
return req
133129
}
134130

135-
func outputResult(p *print.Printer, outputFormat string, schedules []serverbackup.BackupSchedule) error {
131+
func outputResult(p *print.Printer, outputFormat, serverLabel string, schedules []serverbackup.BackupSchedule) error {
136132
return p.OutputResult(outputFormat, schedules, func() error {
133+
if len(schedules) == 0 {
134+
p.Outputf("No backup schedules found for server %s\n", serverLabel)
135+
return nil
136+
}
137137
table := tables.NewTable()
138138
table.SetHeader("SCHEDULE ID", "SCHEDULE NAME", "ENABLED", "RRULE", "BACKUP NAME", "BACKUP RETENTION DAYS", "BACKUP VOLUME IDS")
139139
for i := range schedules {

internal/cmd/server/backup/schedule/list/list_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ func TestBuildRequest(t *testing.T) {
155155
func TestOutputResult(t *testing.T) {
156156
type args struct {
157157
outputFormat string
158+
serverLabel string
158159
schedules []serverbackup.BackupSchedule
159160
}
160161
tests := []struct {
@@ -191,7 +192,7 @@ func TestOutputResult(t *testing.T) {
191192
params := testparams.NewTestParams()
192193
for _, tt := range tests {
193194
t.Run(tt.name, func(t *testing.T) {
194-
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.schedules); (err != nil) != tt.wantErr {
195+
if err := outputResult(params.Printer, tt.args.outputFormat, tt.args.serverLabel, tt.args.schedules); (err != nil) != tt.wantErr {
195196
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
196197
}
197198
})

0 commit comments

Comments
 (0)