forked from kramphub/kiya
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.go
46 lines (40 loc) · 993 Bytes
/
profile.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
package kiya
import (
"encoding/json"
"log"
"os"
"path"
"github.com/kramphub/kiya/backend"
)
// Profiles is a collection of profiles as described in the .kiya configuration
var Profiles map[string]backend.Profile
func load(configFile string) (profs map[string]backend.Profile, err error) {
reader, err := os.Open(configLocation(configFile))
defer reader.Close()
if err != nil {
return
}
err = json.NewDecoder(reader).Decode(&profs)
// ensure profile knows label
for l, p := range profs {
each := p
each.Label = l
profs[l] = each
}
return
}
func configLocation(configFile string) string {
location := configFile
if len(location) == 0 {
location = path.Join(os.Getenv("HOME"), ".kiya")
}
return location
}
// LoadConfiguration loads the .kiya file
func LoadConfiguration(configFile string) {
profs, err := load(configFile)
if err != nil {
log.Fatal("unable to read/parse kiya configration file ("+configLocation(configFile)+")", err)
}
Profiles = profs
}