aboutsummaryrefslogtreecommitdiffstats
path: root/golib
diff options
context:
space:
mode:
Diffstat (limited to 'golib')
-rw-r--r--golib/filepath.go35
1 files changed, 27 insertions, 8 deletions
diff --git a/golib/filepath.go b/golib/filepath.go
index 476096c..b27ac6f 100644
--- a/golib/filepath.go
+++ b/golib/filepath.go
@@ -52,15 +52,34 @@ func ResolveEnvVar(s string) (string, error) {
vars := re.FindAllStringSubmatch(s, -1)
res := s
for _, v := range vars {
- val := os.Getenv(v[1])
- if val == "" {
- // Specific case to resolved $HOME or ${HOME} on Windows host
- if runtime.GOOS == "windows" && v[1] == "HOME" {
- if usr, err := user.Current(); err == nil {
- val = usr.HomeDir
+ val := ""
+ if v[1] == "EXEPATH" {
+ // Specific case to resolve $EXEPATH or ${EXEPATH} used as current executable path
+ exePath := os.Args[0]
+ ee, _ := os.Executable()
+ exeAbsPath, err := filepath.Abs(ee)
+ if err == nil {
+ exePath, err = filepath.EvalSymlinks(exeAbsPath)
+ if err == nil {
+ exePath = filepath.Dir(ee)
+ } else {
+ exePath = filepath.Dir(exeAbsPath)
+ }
+ }
+ val = exePath
+
+ } else {
+ // Get env var value
+ val = os.Getenv(v[1])
+ if val == "" {
+ // Specific case to resolved $HOME or ${HOME} on Windows host
+ if runtime.GOOS == "windows" && v[1] == "HOME" {
+ if usr, err := user.Current(); err == nil {
+ val = usr.HomeDir
+ }
+ } else {
+ return res, fmt.Errorf("ERROR: %s env variable not defined", v[1])
}
- } else {
- return res, fmt.Errorf("ERROR: %s env variable not defined", v[1])
}
}