-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
50 lines (42 loc) · 953 Bytes
/
config.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
package main
import (
"fmt"
"io/ioutil"
"strings"
)
var CONFIG_DOCS_PATH = "/Documents/sb/" // based on the $HOME directory
var CONFIG_EDITOR = "nano"
func loadConfig() {
configFilePath := getHomeDir() + "/.sbrc"
if !isFileExist(configFilePath) {
// fmt.Println("Config file not found! Create .sbrc in your home directory.")
return
}
data, err := ioutil.ReadFile(configFilePath)
if err != nil {
fmt.Printf("Error while reading .sbrc: %v\n", err)
return
}
parseConfig(string(data))
}
func parseConfig(content string) {
words := strings.Fields(content)
for i := 0; i < len(words); i++ {
switch words[i] {
case "set":
// check the length for property and value
if len(words) < i+2+1 {
return
}
configSetCommand(words[i+1], words[i+2])
}
}
}
func configSetCommand(property string, value string) {
switch property {
case "editor":
CONFIG_EDITOR = value
case "docspath":
CONFIG_DOCS_PATH = value
}
}