diff options
author | Felix Lange <fjl@twurst.com> | 2016-09-16 17:53:50 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-09-16 21:24:31 +0800 |
commit | b42a5b118f1aa7ac1235547c8594146978941401 (patch) | |
tree | 5a0a56308fe3137f1c9c69394281dadfc4551f37 /cmd/utils/customflags.go | |
parent | eeb322ae649c4a1a32430cdddfffed70f509181e (diff) | |
download | go-tangerine-b42a5b118f1aa7ac1235547c8594146978941401.tar.gz go-tangerine-b42a5b118f1aa7ac1235547c8594146978941401.tar.zst go-tangerine-b42a5b118f1aa7ac1235547c8594146978941401.zip |
common, node: move datadir defaults into package node
Diffstat (limited to 'cmd/utils/customflags.go')
-rw-r--r-- | cmd/utils/customflags.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/cmd/utils/customflags.go b/cmd/utils/customflags.go index 5cbccfe98..11c92d451 100644 --- a/cmd/utils/customflags.go +++ b/cmd/utils/customflags.go @@ -137,9 +137,19 @@ func (self *DirectoryFlag) Set(value string) { // Note, it has limitations, e.g. ~someuser/tmp will not be expanded func expandPath(p string) string { if strings.HasPrefix(p, "~/") || strings.HasPrefix(p, "~\\") { - if user, err := user.Current(); err == nil { - p = user.HomeDir + p[1:] + if home := homeDir(); home != "" { + p = home + p[1:] } } return path.Clean(os.ExpandEnv(p)) } + +func homeDir() string { + if home := os.Getenv("HOME"); home != "" { + return home + } + if usr, err := user.Current(); err == nil { + return usr.HomeDir + } + return "" +} |