github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/cf/configuration/confighelpers/config_helpers.go (about) 1 package confighelpers 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 "runtime" 8 ) 9 10 func DefaultFilePath() (string, error) { 11 var homeDir string 12 13 if os.Getenv("CF_HOME") != "" { 14 homeDir = os.Getenv("CF_HOME") 15 16 if _, err := os.Stat(homeDir); os.IsNotExist(err) { 17 return "", fmt.Errorf("Error locating CF_HOME folder '%s'", homeDir) 18 } 19 } else { 20 homeDir = userHomeDir() 21 } 22 23 return filepath.Join(homeDir, ".cf", "config.json"), nil 24 } 25 26 // See: http://stackoverflow.com/questions/7922270/obtain-users-home-directory 27 // we can't cross compile using cgo and use user.Current() 28 var userHomeDir = func() string { 29 30 if runtime.GOOS == "windows" { 31 home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH") 32 if home == "" { 33 home = os.Getenv("USERPROFILE") 34 } 35 return home 36 } 37 38 return os.Getenv("HOME") 39 } 40 41 var PluginRepoDir = func() string { 42 if os.Getenv("CF_PLUGIN_HOME") != "" { 43 return os.Getenv("CF_PLUGIN_HOME") 44 } 45 46 return userHomeDir() 47 }