@@ -18,6 +18,7 @@ package main
1818
1919import (
2020 "errors"
21+ "fmt"
2122 "os"
2223 "pb/cmd"
2324 "pb/pkg/config"
@@ -140,18 +141,31 @@ func main() {
140141 Profiles : map [string ]config.Profile {"demo" : defaultInitialProfile ()},
141142 DefaultProfile : "demo" ,
142143 }
143- config .WriteConfigToFile (& conf )
144+ err = config .WriteConfigToFile (& conf )
145+ if err != nil {
146+ fmt .Printf ("failed to write to file %v\n " , err )
147+ os .Exit (1 )
148+ }
144149 } else {
145- // updates the demo profile for existing users
146- _ , exists := previousConfig .Profiles ["demo" ]
150+ // Only update the " demo" profile without overwriting other profiles
151+ demoProfile , exists := previousConfig .Profiles ["demo" ]
147152 if exists {
148- conf := config.Profile {
149- URL : "http://demo.parseable.com" ,
150- Username : "admin" ,
151- Password : "admin" ,
152- }
153- previousConfig .Profiles ["demo" ] = conf
154- config .WriteConfigToFile (previousConfig )
153+ // Update fields in the demo profile only
154+ demoProfile .URL = "http://demo.parseable.com"
155+ demoProfile .Username = "admin"
156+ demoProfile .Password = "admin"
157+ previousConfig .Profiles ["demo" ] = demoProfile
158+ } else {
159+ // Add the "demo" profile if it doesn't exist
160+ previousConfig .Profiles ["demo" ] = defaultInitialProfile ()
161+ previousConfig .DefaultProfile = "demo" // Optional: set as default if needed
162+ }
163+
164+ // Write the updated configuration back to file
165+ err = config .WriteConfigToFile (previousConfig )
166+ if err != nil {
167+ fmt .Printf ("failed to write to existing file %v\n " , err )
168+ os .Exit (1 )
155169 }
156170 }
157171
0 commit comments