forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_helpers.go
62 lines (48 loc) · 1.23 KB
/
config_helpers.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
61
62
package confighelpers
import (
"fmt"
"os"
"path/filepath"
"runtime"
)
func homeDir() (string, error) {
var homeDir string
if os.Getenv("CF_HOME") != "" {
homeDir = os.Getenv("CF_HOME")
if _, err := os.Stat(homeDir); os.IsNotExist(err) {
return "", fmt.Errorf("Error locating CF_HOME folder '%s'", homeDir)
}
} else {
homeDir = userHomeDir()
}
return homeDir, nil
}
func DefaultFilePath() (string, error) {
homeDir, err := homeDir()
if err != nil {
return "", err
}
return filepath.Join(homeDir, ".cf", "config.json"), nil
}
// See: http://stackoverflow.com/questions/7922270/obtain-users-home-directory
// we can't cross compile using cgo and use user.Current()
var userHomeDir = func() string {
if runtime.GOOS == "windows" {
home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
if home == "" {
home = os.Getenv("USERPROFILE")
}
return home
}
return os.Getenv("HOME")
}
var PluginRepoDir = func() string {
if os.Getenv("CF_PLUGIN_HOME") != "" {
return os.Getenv("CF_PLUGIN_HOME")
}
// Ignore the error here because we expect that the directory which is
// ostensibly created in this call shall have already been created by
// DefaultFilePath().
pluginDir, _ := homeDir()
return pluginDir
}