@@ -112,7 +112,7 @@ func (c *Config) InitConfig() {
112112 }
113113 LocalConfigFile := ""
114114 if c .LocalConfigFile == "" {
115- LocalConfigFile = filepath .Join (workspaceFolder , "hookdeck.toml" )
115+ LocalConfigFile = filepath .Join (workspaceFolder , ". hookdeck/config .toml" )
116116 } else {
117117 if filepath .IsAbs (c .LocalConfigFile ) {
118118 LocalConfigFile = c .LocalConfigFile
@@ -203,10 +203,10 @@ func (c *Config) EditConfig() error {
203203}
204204
205205// UseWorkspace selects the active workspace to be used
206- func (c * Config ) UseWorkspace (teamId string , teamMode string ) error {
206+ func (c * Config ) UseWorkspace (local bool , teamId string , teamMode string ) error {
207207 c .Profile .TeamID = teamId
208208 c .Profile .TeamMode = teamMode
209- return c .Profile .SaveProfile ()
209+ return c .Profile .SaveProfile (local )
210210}
211211
212212func (c * Config ) ListProfiles () []string {
@@ -248,29 +248,26 @@ func (c *Config) RemoveAllProfiles() error {
248248
249249// Construct the config struct from flags > local config > global config
250250func (c * Config ) constructConfig () {
251- c .Color = getStringConfig (c .Color , c .LocalConfig .GetString ("color" ) , c .GlobalConfig .GetString (("color" )) , "auto" )
252- c .LogLevel = getStringConfig (c .LogLevel , c .LocalConfig .GetString ("log" ) , c .GlobalConfig .GetString (("log" )) , "info" )
253- c .APIBaseURL = getStringConfig (c .APIBaseURL , c .LocalConfig .GetString ("api_base" ) , c .GlobalConfig .GetString (("api_base" )) , hookdeck .DefaultAPIBaseURL )
254- c .DashboardBaseURL = getStringConfig (c .DashboardBaseURL , c .LocalConfig .GetString ("dashboard_base" ) , c .GlobalConfig .GetString (("dashboard_base" )) , hookdeck .DefaultDashboardBaseURL )
255- c .ConsoleBaseURL = getStringConfig (c .ConsoleBaseURL , c .LocalConfig .GetString ("console_base" ) , c .GlobalConfig .GetString (("console_base" )) , hookdeck .DefaultConsoleBaseURL )
256- c .WSBaseURL = getStringConfig (c .WSBaseURL , c .LocalConfig .GetString ("ws_base" ) , c .GlobalConfig .GetString (("ws_base" )) , hookdeck .DefaultWebsocektURL )
257- c .Profile .Name = getStringConfig (c .Profile .Name , c .LocalConfig .GetString ("profile" ) , c .GlobalConfig .GetString (("profile" )) , hookdeck .DefaultProfileName )
258- c .Profile .APIKey = getStringConfig (c .Profile .APIKey , c .LocalConfig .GetString ("api_key" ) , c .GlobalConfig .GetString ((c .Profile .GetConfigField ("api_key" ))) , "" )
259- c .Profile .TeamID = getStringConfig (c .Profile .TeamID , c .LocalConfig .GetString ("team_id" ) , c .GlobalConfig .GetString ((c .Profile .GetConfigField ("team_id" ))) , "" )
260- c .Profile .TeamMode = getStringConfig (c .Profile .TeamMode , c .LocalConfig .GetString ("team_mode" ) , c .GlobalConfig .GetString ((c .Profile .GetConfigField ("team_mode" ))), "" )
251+ c .Color = getStringConfig ([] string { c .Color , c .LocalConfig .GetString ("color" ) , c .GlobalConfig .GetString (("color" )) , "auto" } )
252+ c .LogLevel = getStringConfig ([] string { c .LogLevel , c .LocalConfig .GetString ("log" ) , c .GlobalConfig .GetString (("log" )) , "info" } )
253+ c .APIBaseURL = getStringConfig ([] string { c .APIBaseURL , c .LocalConfig .GetString ("api_base" ) , c .GlobalConfig .GetString (("api_base" )) , hookdeck .DefaultAPIBaseURL } )
254+ c .DashboardBaseURL = getStringConfig ([] string { c .DashboardBaseURL , c .LocalConfig .GetString ("dashboard_base" ) , c .GlobalConfig .GetString (("dashboard_base" )) , hookdeck .DefaultDashboardBaseURL } )
255+ c .ConsoleBaseURL = getStringConfig ([] string { c .ConsoleBaseURL , c .LocalConfig .GetString ("console_base" ) , c .GlobalConfig .GetString (("console_base" )) , hookdeck .DefaultConsoleBaseURL } )
256+ c .WSBaseURL = getStringConfig ([] string { c .WSBaseURL , c .LocalConfig .GetString ("ws_base" ) , c .GlobalConfig .GetString (("ws_base" )) , hookdeck .DefaultWebsocektURL } )
257+ c .Profile .Name = getStringConfig ([] string { c .Profile .Name , c .LocalConfig .GetString ("profile" ) , c .GlobalConfig .GetString (("profile" )) , hookdeck .DefaultProfileName } )
258+ c .Profile .APIKey = getStringConfig ([] string { c .Profile .APIKey , c .LocalConfig .GetString ("api_key" ) , c .GlobalConfig .GetString ((c .Profile .GetConfigField ("api_key" ))) , "" } )
259+ c .Profile .TeamID = getStringConfig ([] string { c .Profile .TeamID , c .LocalConfig .GetString ("workspace_id" ) , c . LocalConfig . GetString ( " team_id" ) , c .GlobalConfig .GetString ((c .Profile .GetConfigField ("workspace_id" ))) , c . GlobalConfig . GetString (( c . Profile . GetConfigField ( " team_id" ))) , "" } )
260+ c .Profile .TeamMode = getStringConfig ([] string { c .Profile .TeamMode , c .LocalConfig .GetString ("workspace_mode" ) , c . LocalConfig . GetString ( " team_mode" ) , c .GlobalConfig .GetString ((c .Profile .GetConfigField ("workspace_mode" ))) , c . GlobalConfig . GetString (( c . Profile . GetConfigField ( " team_mode" ))) , "" } )
261261}
262262
263- func getStringConfig (v1 string , v2 string , v3 string , v4 string ) string {
264- if v1 != "" {
265- return v1
266- }
267- if v2 != "" {
268- return v2
269- }
270- if v3 != "" {
271- return v3
263+ func getStringConfig (values []string ) string {
264+ for _ , str := range values {
265+ if str != "" {
266+ return str
267+ }
272268 }
273- return v4
269+
270+ return values [len (values )- 1 ]
274271}
275272
276273// isProfile identifies whether a value in the config pertains to a profile.
0 commit comments