@@ -6,11 +6,13 @@ import (
66 "errors"
77 "fmt"
88 "os"
9+ "os/exec"
910 "reflect"
1011 "strings"
1112
1213 "github.com/fatih/color"
1314 "github.com/scaleway/scaleway-cli/v2/core"
15+ "github.com/scaleway/scaleway-cli/v2/internal/config"
1416 "github.com/scaleway/scaleway-cli/v2/internal/interactive"
1517 "github.com/scaleway/scaleway-cli/v2/internal/tabwriter"
1618 "github.com/scaleway/scaleway-cli/v2/internal/terminal"
@@ -34,6 +36,7 @@ func GetCommands() *core.Commands {
3436 configInfoCommand (),
3537 configImportCommand (),
3638 configValidateCommand (),
39+ configEditCommand (),
3740 )
3841}
3942
@@ -770,6 +773,38 @@ The command goes through each profile present in the config file and validates i
770773 }
771774}
772775
776+ func configEditCommand () * core.Command {
777+ type configEditArgs struct {}
778+
779+ return & core.Command {
780+ Namespace : "config" ,
781+ Resource : "edit" ,
782+ Short : "Edit the configuration file" ,
783+ Long : "Edit the configuration file with the default editor" ,
784+ ArgsType : reflect .TypeOf (configEditArgs {}),
785+ AllowAnonymousClient : true ,
786+ Run : func (ctx context.Context , _ any ) (i any , e error ) {
787+ configPath := core .ExtractConfigPath (ctx )
788+
789+ defaultEditor := config .GetDefaultEditor ()
790+ args := []string {configPath }
791+
792+ cmd := exec .Command (defaultEditor , args ... )
793+ cmd .Stdin = os .Stdin
794+ cmd .Stdout = os .Stdout
795+
796+ err := cmd .Run ()
797+ if err != nil {
798+ return nil , fmt .Errorf ("failed to edit file %q: %w" , configPath , err )
799+ }
800+
801+ return & core.SuccessResult {
802+ Message : "successfully wrote config" ,
803+ }, nil
804+ },
805+ }
806+ }
807+
773808// Helper functions
774809func getProfileValue (profile * scw.Profile , fieldName string ) (any , error ) {
775810 field , err := getProfileField (profile , fieldName )
0 commit comments