From 108cd021d11849ca19c0052cdcb7f7f2a3d20d6e Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Thu, 25 Mar 2021 11:08:26 +0100 Subject: [PATCH] opportunistic absolute file path --- parsers.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/parsers.go b/parsers.go index d80a460..fc588bc 100644 --- a/parsers.go +++ b/parsers.go @@ -2,7 +2,8 @@ package envconf import ("strconv" "fmt" "errors" - "path/filepath" + "os" + "path" "time") func parseInt(key string, str string)(ret cValue) { @@ -35,12 +36,16 @@ func parseBool(key string, str string)(ret cValue) { return } -func parseDirectory(key string, str string)(ret cValue) { - val, err := filepath.Abs(str) +func parseDirectory(_ string, str string)(ret cValue) { + wd, err := os.Getwd() if err == nil { - ret.strval = val + if path.IsAbs(str) { + ret.strval = path.Clean(str) + } else { + ret.strval = path.Join(wd, str) + } } else { - ret.err = errors.New(fmt.Sprintf(`Environment variable "%s" is not of type directory.`, key)) + ret.strval = path.Clean(str) } return }