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
36 changes: 36 additions & 0 deletions internal/namespaces/documentdb/v1beta1/custom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package documentdb

import (
"github.com/fatih/color"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/internal/human"
documentdb "github.com/scaleway/scaleway-sdk-go/api/documentdb/v1beta1"
)

var (
instanceStatusMarshalSpecs = human.EnumMarshalSpecs{
documentdb.InstanceStatusUnknown: &human.EnumMarshalSpec{Attribute: color.Faint, Value: "unknown"},
documentdb.InstanceStatusReady: &human.EnumMarshalSpec{Attribute: color.FgGreen, Value: "ready"},
documentdb.InstanceStatusProvisioning: &human.EnumMarshalSpec{Attribute: color.FgBlue, Value: "provisioning"},
documentdb.InstanceStatusConfiguring: &human.EnumMarshalSpec{Attribute: color.FgBlue, Value: "configuring"},
documentdb.InstanceStatusDeleting: &human.EnumMarshalSpec{Attribute: color.FgBlue, Value: "deleting"},
documentdb.InstanceStatusError: &human.EnumMarshalSpec{Attribute: color.FgRed, Value: "error"},
documentdb.InstanceStatusAutohealing: &human.EnumMarshalSpec{Attribute: color.FgBlue, Value: "auto-healing"},
documentdb.InstanceStatusLocked: &human.EnumMarshalSpec{Attribute: color.FgRed, Value: "locked"},
documentdb.InstanceStatusInitializing: &human.EnumMarshalSpec{Attribute: color.FgBlue, Value: "initialized"},
documentdb.InstanceStatusDiskFull: &human.EnumMarshalSpec{Attribute: color.FgRed, Value: "disk_full"},
documentdb.InstanceStatusBackuping: &human.EnumMarshalSpec{Attribute: color.FgBlue, Value: "backuping"},
documentdb.InstanceStatusSnapshotting: &human.EnumMarshalSpec{Attribute: color.FgBlue},
documentdb.InstanceStatusRestarting: &human.EnumMarshalSpec{Attribute: color.FgBlue},
}
)

func GetCommands() *core.Commands {
cmds := GetGeneratedCommands()

human.RegisterMarshalerFunc(documentdb.InstanceStatus(""), human.EnumMarshalFunc(instanceStatusMarshalSpecs))

cmds.MustFind("document-db", "engine", "list").Override(engineListBuilder)

return cmds
}
56 changes: 56 additions & 0 deletions internal/namespaces/documentdb/v1beta1/custom_engine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package documentdb

import (
"context"
"time"

"github.com/scaleway/scaleway-cli/v2/internal/core"
documentdb "github.com/scaleway/scaleway-sdk-go/api/documentdb/v1beta1"
)

func engineListBuilder(c *core.Command) *core.Command {
type customEngine struct {
Name string `json:"name"`
EngineType string `json:"engine_type"`
EndOfLife *time.Time `json:"end_of_life"`
}

c.View = &core.View{
Fields: []*core.ViewField{
{
Label: "Name",
FieldName: "Name",
},
{
Label: "Engine Type",
FieldName: "EngineType",
},
{
Label: "End of Life",
FieldName: "EndOfLife",
},
},
}

c.AddInterceptors(func(ctx context.Context, argsI interface{}, runner core.CommandRunner) (i interface{}, err error) {
listEngineResp, err := runner(ctx, argsI)
if err != nil {
return listEngineResp, err
}
engineList := listEngineResp.([]*documentdb.DatabaseEngine)
var res []customEngine
for _, engine := range engineList {
for _, version := range engine.Versions {
res = append(res, customEngine{
Name: version.Name,
EngineType: engine.Name,
EndOfLife: version.EndOfLife,
})
}
}

return res, nil
})

return c
}
7 changes: 6 additions & 1 deletion internal/namespaces/get_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
cockpit "github.com/scaleway/scaleway-cli/v2/internal/namespaces/cockpit/v1beta1"
configNamespace "github.com/scaleway/scaleway-cli/v2/internal/namespaces/config"
container "github.com/scaleway/scaleway-cli/v2/internal/namespaces/container/v1beta1"
documentdb "github.com/scaleway/scaleway-cli/v2/internal/namespaces/documentdb/v1beta1"
domain "github.com/scaleway/scaleway-cli/v2/internal/namespaces/domain/v2beta1"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/feedback"
flexibleip "github.com/scaleway/scaleway-cli/v2/internal/namespaces/flexibleip/v1alpha1"
Expand All @@ -39,12 +40,13 @@ import (
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/vpc/v2"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/vpcgw/v1"
webhosting "github.com/scaleway/scaleway-cli/v2/internal/namespaces/webhosting/v1alpha1"
"github.com/scaleway/scaleway-sdk-go/scw"
)

var labs = os.Getenv("SCW_ENABLE_LABS") == "true"

// Enable beta in the code when products are in beta
// var beta = os.Getenv(scw.ScwEnableBeta) == "true"
var beta = os.Getenv(scw.ScwEnableBeta) == "true"

// GetCommands returns a list of all commands in the CLI.
// It is used by both scw and scw-qa.
Expand Down Expand Up @@ -91,6 +93,9 @@ func GetCommands() *core.Commands {
if labs {
commands.Merge(ipfs.GetCommands())
}
if beta {
commands.Merge(documentdb.GetCommands())
}

return commands
}