-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
60 lines (52 loc) · 1.33 KB
/
init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"log"
"os"
"runtime"
"strings"
"github.com/jkueh/roo/util"
)
func init() {
// Set debug mode via environment variable
debug = strings.ToLower(os.Getenv("DEBUG")) == "true"
verbose = strings.ToLower(os.Getenv("VERBOSE")) == "true"
if debug {
log.Println("Debug mode enabled.")
}
if verbose {
log.Println("Verbose mode enabled.")
}
var homeDir string
var err error
if homeDir == "" {
if runtime.GOOS == "windows" {
homeDir = os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
if homeDir == "" {
homeDir = os.Getenv("USERPROFILE")
}
} else { // We assume *NIX in bash otherwise
homeDir = os.Getenv("HOME")
}
if homeDir == "" {
log.Fatalln("Internal error: Unable to determine homeDir")
}
}
if configDir == "" {
configDir = strings.Join([]string{homeDir, ".roo"}, string(os.PathSeparator))
}
err = util.EnsureDirExists(configDir, 0700)
if err != nil {
log.Fatalln("Unable to create configDir:", err)
}
// Set the default config file path.
if configFile == "" {
configFile = strings.Join([]string{configDir, "config.yaml"}, string(os.PathSeparator))
}
if cacheDir == "" {
cacheDir = strings.Join([]string{configDir, "cache"}, string(os.PathSeparator))
}
err = util.EnsureDirExists(cacheDir, 0700)
if err != nil {
log.Fatalln("Unable to create cacheDir:", err)
}
}