From 298171841e22668fe871a18e9a7b81c6cf725350 Mon Sep 17 00:00:00 2001 From: shilangyu Date: Thu, 21 Jan 2021 11:04:04 +0100 Subject: [PATCH] Add support for env:SCOOP, closes #11 --- main.go | 19 ++++++++++++++++--- util.go | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index bf6bbe4..5e88c5a 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,21 @@ type match struct { type matchMap = map[string][]match +// resolves the path to scoop folder +func scoopHome() (res string) { + if value, ok := os.LookupEnv("SCOOP"); ok { + res = value + } else { + var err error + res, err = os.UserHomeDir() + checkWith(err, "Could not determine home dir") + + res += "\\scoop" + } + + return +} + func main() { args := parseArgs() @@ -29,9 +44,7 @@ func main() { } // get buckets path - homeDir, err := os.UserHomeDir() - checkWith(err, "Could not determine home dir") - bucketsPath := homeDir + "\\scoop\\buckets" + bucketsPath := scoopHome() + "\\buckets" // get specific buckets buckets, err := ioutil.ReadDir(bucketsPath) diff --git a/util.go b/util.go index 8d41d9a..2541144 100644 --- a/util.go +++ b/util.go @@ -8,7 +8,7 @@ import ( func checkWith(err error, msg string) { if err != nil { - log.Fatal(msg) + log.Fatal(msg, " - ", err) } }