chore: refactors config.Paths

Refactors the reading of multiple envvars out of `config.Paths` in order
to facilitate cleaner unit-testing.
This commit is contained in:
Chris Lane
2020-01-30 18:19:43 -05:00
parent d4c6200702
commit 6912771c39
2 changed files with 18 additions and 11 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt"
"os"
"runtime"
"strings"
"github.com/docopt/docopt-go"
@ -31,8 +32,15 @@ func main() {
os.Exit(0)
}
// read the envvars into a map of strings
envvars := map[string]string{}
for _, e := range os.Environ() {
pair := strings.SplitN(e, "=", 2)
envvars[pair[0]] = pair[1]
}
// load the os-specifc paths at which the config file may be located
confpaths, err := config.Paths(runtime.GOOS)
confpaths, err := config.Paths(runtime.GOOS, envvars)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to load config: %v\n", err)
os.Exit(1)