From fc3d477d972d13e8d1d08f6ac5d8395c9cbb1590 Mon Sep 17 00:00:00 2001 From: Ryan Slade Date: Fri, 29 May 2020 11:49:11 +0200 Subject: [PATCH] Handle ~/ prefix in config path We handle this special case so that the home directory is expanded. This is only an issue when the path is specified using an equal sign, eg. -config=~/foo.json We just fix this one specific edge case since config files are being deprecated soon. --- cmd/src/main.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/src/main.go b/cmd/src/main.go index 9060a88427..e3bcc3b642 100644 --- a/cmd/src/main.go +++ b/cmd/src/main.go @@ -75,12 +75,15 @@ type config struct { func readConfig() (*config, error) { cfgPath := *configPath userSpecified := *configPath != "" + + user, err := user.Current() + if err != nil { + return nil, err + } if !userSpecified { - user, err := user.Current() - if err != nil { - return nil, err - } cfgPath = filepath.Join(user.HomeDir, "src-config.json") + } else if strings.HasPrefix(cfgPath, "~/") { + cfgPath = filepath.Join(user.HomeDir, cfgPath[2:]) } data, err := ioutil.ReadFile(os.ExpandEnv(cfgPath)) if err != nil && (!os.IsNotExist(err) || userSpecified) {