@@ -3,6 +3,8 @@ package utils
33import (
44 "context"
55 "fmt"
6+ "os"
7+ "path/filepath"
68 "sort"
79 "strings"
810
@@ -121,15 +123,34 @@ func getProfileName(fsys afero.Fs) string {
121123 if prof := viper .GetString ("PROFILE" ); viper .IsSet ("PROFILE" ) {
122124 fmt .Fprintln (debuglogger , "Loading profile from flag:" , prof )
123125 return prof
124- } else if content , err := afero .ReadFile (fsys , ProfilePath ); err == nil {
125- fmt .Fprintln (debuglogger , "Loading profile from file:" , ProfilePath )
126+ } else if profilePath , err := getProfilePath (); err != nil {
127+ fmt .Fprintln (debuglogger , err )
128+ return prof
129+ } else if content , err := afero .ReadFile (fsys , profilePath ); err == nil {
130+ fmt .Fprintln (debuglogger , "Loading profile from file:" , profilePath )
126131 return string (content )
127132 } else {
128133 fmt .Fprintln (debuglogger , err )
129134 return prof
130135 }
131136}
132137
138+ func getProfilePath () (string , error ) {
139+ home , err := os .UserHomeDir ()
140+ if err != nil {
141+ return "" , errors .Errorf ("failed to get $HOME directory: %w" , err )
142+ }
143+ return filepath .Join (home , ".supabase" , "profile" ), nil
144+ }
145+
146+ func SaveProfileName (prof string , fsys afero.Fs ) error {
147+ profilePath , err := getProfilePath ()
148+ if err != nil {
149+ return err
150+ }
151+ return WriteFile (profilePath , []byte (prof ), fsys )
152+ }
153+
133154func AwsRegions () []string {
134155 result := make ([]string , len (allProfiles [0 ].ProjectRegions ))
135156 for i , region := range allProfiles [0 ].ProjectRegions {
0 commit comments