From 339a0146143c8a30b9b1e89a5426ac4c9805d57f Mon Sep 17 00:00:00 2001 From: morganamilo Date: Sun, 12 Aug 2018 04:11:34 +0100 Subject: [PATCH] Go back to using os.Getenv Most programs seem to take an empty string as being the same as unset. Even if they are technically different. This makes it easier to unset variables via `VARIABLE= yay --foo`. --- main.go | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/main.go b/main.go index 73cf2f4b..53a6db58 100644 --- a/main.go +++ b/main.go @@ -11,30 +11,18 @@ import ( ) func setPaths() error { - if _configHome, set := os.LookupEnv("XDG_CONFIG_HOME"); set { - if _configHome == "" { - return fmt.Errorf("XDG_CONFIG_HOME set but empty") - } - configHome = filepath.Join(_configHome, "yay") - } else if _configHome, set := os.LookupEnv("HOME"); set { - if _configHome == "" { - return fmt.Errorf("HOME set but empty") - } - configHome = filepath.Join(_configHome, ".config/yay") + if configHome = os.Getenv("XDG_CONFIG_HOME"); configHome != "" { + configHome = filepath.Join(configHome, "yay") + } else if configHome = os.Getenv("HOME"); configHome != "" { + configHome = filepath.Join(configHome, ".config/yay") } else { return fmt.Errorf("XDG_CONFIG_HOME and HOME unset") } - if _cacheHome, set := os.LookupEnv("XDG_CACHE_HOME"); set { - if _cacheHome == "" { - return fmt.Errorf("XDG_CACHE_HOME set but empty") - } - cacheHome = filepath.Join(_cacheHome, "yay") - } else if _cacheHome, set := os.LookupEnv("HOME"); set { - if _cacheHome == "" { - return fmt.Errorf("XDG_CACHE_HOME set but empty") - } - cacheHome = filepath.Join(_cacheHome, ".cache/yay") + if cacheHome = os.Getenv("XDG_CACHE_HOME"); cacheHome != "" { + cacheHome = filepath.Join(cacheHome, "yay") + } else if cacheHome = os.Getenv("HOME"); cacheHome != "" { + cacheHome = filepath.Join(cacheHome, ".cache/yay") } else { return fmt.Errorf("XDG_CACHE_HOME and HOME unset") }