Skip to content
Merged
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
4 changes: 3 additions & 1 deletion internal/human/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ func marshalSlice(slice reflect.Value, opt *MarshalOpt) (string, error) {
opt.Fields = getDefaultFieldsOpt(itemType)
}

subOpts := &MarshalOpt{TableCell: true}

// Validate that all field exist
for _, f := range opt.Fields {
_, err := gofields.GetType(itemType, f.FieldName)
Expand Down Expand Up @@ -304,7 +306,7 @@ func marshalSlice(slice reflect.Value, opt *MarshalOpt) (string, error) {
case fieldValue.Type().Kind() == reflect.Slice:
str, err = marshalInlineSlice(fieldValue)
default:
str, err = Marshal(fieldValue.Interface(), opt)
str, err = Marshal(fieldValue.Interface(), subOpts)
}
if err != nil {
return "", err
Expand Down
3 changes: 3 additions & 0 deletions internal/human/specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ type MarshalOpt struct {
Title string
Fields []*MarshalFieldOpt
Sections []*MarshalSection

// Is set to true if we are marshaling a table cell
TableCell bool
}

type MarshalFieldOpt struct {
Expand Down
19 changes: 14 additions & 5 deletions internal/namespaces/rdb/v1/custom_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ func instanceMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error)
}

func backupScheduleMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
backupSchedule := i.(rdb.BackupSchedule)

if opt.TableCell {
if backupSchedule.Disabled {
return "Disabled", nil
}
return "Enabled", nil
}

// To avoid recursion of human.Marshal we create a dummy type
type LocalBackupSchedule rdb.BackupSchedule
type tmp struct {
Expand All @@ -82,17 +91,17 @@ func backupScheduleMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string,
Retention *scw.Duration `json:"retention"`
}

backupSchedule := tmp{
LocalBackupSchedule: LocalBackupSchedule(i.(rdb.BackupSchedule)),
localBackupSchedule := tmp{
LocalBackupSchedule: LocalBackupSchedule(backupSchedule),
Frequency: &scw.Duration{
Seconds: int64(i.(rdb.BackupSchedule).Frequency) * 3600,
Seconds: int64(backupSchedule.Frequency) * 3600,
},
Retention: &scw.Duration{
Seconds: int64(i.(rdb.BackupSchedule).Retention) * 24 * 3600,
Seconds: int64(backupSchedule.Retention) * 24 * 3600,
},
}

str, err := human.Marshal(backupSchedule, opt)
str, err := human.Marshal(localBackupSchedule, opt)
if err != nil {
return "", err
}
Expand Down
10 changes: 10 additions & 0 deletions internal/namespaces/rdb/v1/custom_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ import (
"github.com/scaleway/scaleway-cli/internal/core"
)

func Test_ListInstance(t *testing.T) {
t.Run("Simple", core.Test(&core.TestConfig{
Commands: GetCommands(),
BeforeFunc: createInstance("PostgreSQL-12"),
Cmd: "scw rdb instance list",
Check: core.TestCheckGolden(),
AfterFunc: deleteInstance(),
}))
}

func Test_CloneInstance(t *testing.T) {
t.Run("Simple", core.Test(&core.TestConfig{
Commands: GetCommands(),
Expand Down
Loading