@@ -15,6 +15,7 @@ import (
1515 "net/url"
1616 "os"
1717 "path/filepath"
18+ "runtime"
1819 "strings"
1920 "time"
2021
@@ -205,23 +206,30 @@ func generateConfig(cfgFile string) (err error) {
205206 }
206207
207208 // Generate the initial config file
208- const CFG = `[certs]
209- cachain = "%s"
210- cert = "/path/to/your/certificate/here"
211-
212- [general]
213- cloud = "https://dbhub.io:5550"
214-
215- [user]
216- name = "Your Name"
217- `
218209 var f * os.File
219210 f , err = os .Create (cfgFile )
220211 if err != nil {
221212 return
222213 }
223214 defer f .Close ()
224- _ , err = fmt .Fprintf (f , CFG , chainFile )
215+ lineEnd := "\n "
216+ warnMsg := ""
217+ if runtime .GOOS == "windows" {
218+ lineEnd = "\r \n "
219+ warnMsg = " # On Windows, directory slashes need to be doubled up otherwise parsing fails."
220+ }
221+ safeChainFile := strings .ReplaceAll (chainFile , `\` , `\\` )
222+ certPath := fmt .Sprintf ("%c%s" , os .PathSeparator , filepath .Join ("path" , "to" , "your" , "certificate" , "here" ))
223+ safeCertPath := strings .ReplaceAll (certPath , `\` , `\\` )
224+ _ , err = fmt .Fprint (f , `[certs]` + lineEnd )
225+ _ , err = fmt .Fprint (f , fmt .Sprintf (`cachain = "%s"%s` , safeChainFile , lineEnd ))
226+ _ , err = fmt .Fprint (f , fmt .Sprintf (`cert = "%s"%s%s` , safeCertPath , warnMsg , lineEnd ))
227+ _ , err = fmt .Fprint (f , lineEnd )
228+ _ , err = fmt .Fprint (f , `[general]` + lineEnd )
229+ _ , err = fmt .Fprint (f , `cloud = "https://dbhub.io:5550"` + lineEnd )
230+ _ , err = fmt .Fprint (f , lineEnd )
231+ _ , err = fmt .Fprint (f , `[user]` + lineEnd )
232+ _ , err = fmt .Fprint (f , `name = "Your Name"` + lineEnd )
225233 return
226234}
227235
0 commit comments