Skip to content

Commit 768706e

Browse files
CodelaxMonitob
andauthored
feat(document_db): enable in beta (#3337)
Co-authored-by: jaime Bernabe <[email protected]>
1 parent 7552326 commit 768706e

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package documentdb
2+
3+
import (
4+
"github.com/fatih/color"
5+
"github.com/scaleway/scaleway-cli/v2/internal/core"
6+
"github.com/scaleway/scaleway-cli/v2/internal/human"
7+
documentdb "github.com/scaleway/scaleway-sdk-go/api/documentdb/v1beta1"
8+
)
9+
10+
var (
11+
instanceStatusMarshalSpecs = human.EnumMarshalSpecs{
12+
documentdb.InstanceStatusUnknown: &human.EnumMarshalSpec{Attribute: color.Faint, Value: "unknown"},
13+
documentdb.InstanceStatusReady: &human.EnumMarshalSpec{Attribute: color.FgGreen, Value: "ready"},
14+
documentdb.InstanceStatusProvisioning: &human.EnumMarshalSpec{Attribute: color.FgBlue, Value: "provisioning"},
15+
documentdb.InstanceStatusConfiguring: &human.EnumMarshalSpec{Attribute: color.FgBlue, Value: "configuring"},
16+
documentdb.InstanceStatusDeleting: &human.EnumMarshalSpec{Attribute: color.FgBlue, Value: "deleting"},
17+
documentdb.InstanceStatusError: &human.EnumMarshalSpec{Attribute: color.FgRed, Value: "error"},
18+
documentdb.InstanceStatusAutohealing: &human.EnumMarshalSpec{Attribute: color.FgBlue, Value: "auto-healing"},
19+
documentdb.InstanceStatusLocked: &human.EnumMarshalSpec{Attribute: color.FgRed, Value: "locked"},
20+
documentdb.InstanceStatusInitializing: &human.EnumMarshalSpec{Attribute: color.FgBlue, Value: "initialized"},
21+
documentdb.InstanceStatusDiskFull: &human.EnumMarshalSpec{Attribute: color.FgRed, Value: "disk_full"},
22+
documentdb.InstanceStatusBackuping: &human.EnumMarshalSpec{Attribute: color.FgBlue, Value: "backuping"},
23+
documentdb.InstanceStatusSnapshotting: &human.EnumMarshalSpec{Attribute: color.FgBlue},
24+
documentdb.InstanceStatusRestarting: &human.EnumMarshalSpec{Attribute: color.FgBlue},
25+
}
26+
)
27+
28+
func GetCommands() *core.Commands {
29+
cmds := GetGeneratedCommands()
30+
31+
human.RegisterMarshalerFunc(documentdb.InstanceStatus(""), human.EnumMarshalFunc(instanceStatusMarshalSpecs))
32+
33+
cmds.MustFind("document-db", "engine", "list").Override(engineListBuilder)
34+
35+
return cmds
36+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package documentdb
2+
3+
import (
4+
"context"
5+
"time"
6+
7+
"github.com/scaleway/scaleway-cli/v2/internal/core"
8+
documentdb "github.com/scaleway/scaleway-sdk-go/api/documentdb/v1beta1"
9+
)
10+
11+
func engineListBuilder(c *core.Command) *core.Command {
12+
type customEngine struct {
13+
Name string `json:"name"`
14+
EngineType string `json:"engine_type"`
15+
EndOfLife *time.Time `json:"end_of_life"`
16+
}
17+
18+
c.View = &core.View{
19+
Fields: []*core.ViewField{
20+
{
21+
Label: "Name",
22+
FieldName: "Name",
23+
},
24+
{
25+
Label: "Engine Type",
26+
FieldName: "EngineType",
27+
},
28+
{
29+
Label: "End of Life",
30+
FieldName: "EndOfLife",
31+
},
32+
},
33+
}
34+
35+
c.AddInterceptors(func(ctx context.Context, argsI interface{}, runner core.CommandRunner) (i interface{}, err error) {
36+
listEngineResp, err := runner(ctx, argsI)
37+
if err != nil {
38+
return listEngineResp, err
39+
}
40+
engineList := listEngineResp.([]*documentdb.DatabaseEngine)
41+
var res []customEngine
42+
for _, engine := range engineList {
43+
for _, version := range engine.Versions {
44+
res = append(res, customEngine{
45+
Name: version.Name,
46+
EngineType: engine.Name,
47+
EndOfLife: version.EndOfLife,
48+
})
49+
}
50+
}
51+
52+
return res, nil
53+
})
54+
55+
return c
56+
}

internal/namespaces/get_commands.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
cockpit "github.com/scaleway/scaleway-cli/v2/internal/namespaces/cockpit/v1beta1"
1414
configNamespace "github.com/scaleway/scaleway-cli/v2/internal/namespaces/config"
1515
container "github.com/scaleway/scaleway-cli/v2/internal/namespaces/container/v1beta1"
16+
documentdb "github.com/scaleway/scaleway-cli/v2/internal/namespaces/documentdb/v1beta1"
1617
domain "github.com/scaleway/scaleway-cli/v2/internal/namespaces/domain/v2beta1"
1718
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/feedback"
1819
flexibleip "github.com/scaleway/scaleway-cli/v2/internal/namespaces/flexibleip/v1alpha1"
@@ -39,12 +40,13 @@ import (
3940
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/vpc/v2"
4041
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/vpcgw/v1"
4142
webhosting "github.com/scaleway/scaleway-cli/v2/internal/namespaces/webhosting/v1alpha1"
43+
"github.com/scaleway/scaleway-sdk-go/scw"
4244
)
4345

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

4648
// Enable beta in the code when products are in beta
47-
// var beta = os.Getenv(scw.ScwEnableBeta) == "true"
49+
var beta = os.Getenv(scw.ScwEnableBeta) == "true"
4850

4951
// GetCommands returns a list of all commands in the CLI.
5052
// It is used by both scw and scw-qa.
@@ -91,6 +93,9 @@ func GetCommands() *core.Commands {
9193
if labs {
9294
commands.Merge(ipfs.GetCommands())
9395
}
96+
if beta {
97+
commands.Merge(documentdb.GetCommands())
98+
}
9499

95100
return commands
96101
}

0 commit comments

Comments
 (0)