@@ -17,6 +17,7 @@ import (
1717 "github.com/fatih/color"
1818 "github.com/scaleway/scaleway-cli/v2/core"
1919 "github.com/scaleway/scaleway-cli/v2/core/human"
20+ "github.com/scaleway/scaleway-cli/v2/internal/editor"
2021 "github.com/scaleway/scaleway-cli/v2/internal/interactive"
2122 "github.com/scaleway/scaleway-cli/v2/internal/passwordgenerator"
2223 "github.com/scaleway/scaleway-cli/v2/internal/terminal"
@@ -925,3 +926,89 @@ func instanceConnectCommand() *core.Command {
925926 },
926927 }
927928}
929+
930+ func instanceEditSettingsCommand () * core.Command {
931+ type editSettingsArgs struct {
932+ InstanceID string `arg:"positional,required"`
933+ Region scw.Region `arg:"required"`
934+ Mode editor.MarshalMode
935+ }
936+
937+ return & core.Command {
938+ Namespace : "rdb" ,
939+ Resource : "setting" ,
940+ Verb : "edit" ,
941+ Short : "Edit Database Instance settings in your default editor" ,
942+ Long : `This command opens the current settings of your RDB instance in your $EDITOR.
943+ You can modify the values and save the file to apply the new configuration.` ,
944+ ArgsType : reflect .TypeOf (editSettingsArgs {}),
945+ ArgSpecs : core.ArgSpecs {
946+ {
947+ Name : "instance-id" ,
948+ Short : "ID of the instance" ,
949+ Required : true ,
950+ Positional : true ,
951+ },
952+ editor .MarshalModeArgSpec (), // --mode=yaml|json
953+ core .RegionArgSpec (scw .RegionFrPar , scw .RegionNlAms , scw .RegionPlWaw ),
954+ },
955+ Examples : []* core.Example {
956+ {
957+ Short : "Edit instance settings in YAML" ,
958+ Raw : "scw rdb setting edit 12345678-1234-1234-1234-123456789abc --region=fr-par --mode=yaml" ,
959+ },
960+ {
961+ Short : "Edit instance settings in JSON" ,
962+ Raw : "scw rdb setting edit 12345678-1234-1234-1234-123456789abc --region=fr-par --mode=json" ,
963+ },
964+ },
965+ Run : func (ctx context.Context , argsI interface {}) (interface {}, error ) {
966+ args := argsI .(* editSettingsArgs )
967+
968+ client := core .ExtractClient (ctx )
969+ api := rdbSDK .NewAPI (client )
970+
971+ instance , err := api .GetInstance (& rdbSDK.GetInstanceRequest {
972+ InstanceID : args .InstanceID ,
973+ Region : args .Region ,
974+ })
975+ if err != nil {
976+ return nil , err
977+ }
978+
979+ initialRequest := & rdbSDK.SetInstanceSettingsRequest {
980+ Region : args .Region ,
981+ InstanceID : args .InstanceID ,
982+ Settings : instance .Settings ,
983+ }
984+
985+ editedRequestRaw , err := editor .UpdateResourceEditor (
986+ initialRequest ,
987+ & rdbSDK.SetInstanceSettingsRequest {
988+ Region : args .Region ,
989+ InstanceID : args .InstanceID ,
990+ },
991+ & editor.Config {
992+ PutRequest : true ,
993+ MarshalMode : args .Mode ,
994+ },
995+ )
996+ if err != nil {
997+ return nil , err
998+ }
999+
1000+ editedRequest := editedRequestRaw .(* rdbSDK.SetInstanceSettingsRequest )
1001+
1002+ if reflect .DeepEqual (initialRequest .Settings , editedRequest .Settings ) {
1003+ return & core.SuccessResult {Message : "No changes detected." }, nil
1004+ }
1005+
1006+ _ , err = api .SetInstanceSettings (editedRequest )
1007+ if err != nil {
1008+ return nil , err
1009+ }
1010+
1011+ return & core.SuccessResult {Message : "Settings successfully updated." }, nil
1012+ },
1013+ }
1014+ }
0 commit comments