Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 3793fde

Browse files
committed
Generated config file now works on windows, bump release ver to 0.2.1
Fixes #3
1 parent c5dc88a commit 3793fde

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
)
1818

1919
const (
20-
DIO_VERSION = "0.2.0"
20+
DIO_VERSION = "0.2.1"
2121
)
2222

2323
var (
@@ -55,7 +55,7 @@ func init() {
5555

5656
// Add the global environment variables
5757
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "",
58-
"config file (default is $HOME/.dio/config.toml)")
58+
fmt.Sprintf("config file (default is %s)", filepath.Join("$HOME", ".dio", "config.toml")))
5959
RootCmd.PersistentFlags().StringVar(&cloud, "cloud", "https://dbhub.io:5550",
6060
"Address of the DBHub.io cloud")
6161

cmd/shared.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)