github.com/tooploox/oya@v0.0.21-0.20230524103240-1cda1861aad6/cmd/internal/env.go (about) 1 package internal 2 3 import ( 4 "log" 5 "os" 6 "os/user" 7 "path/filepath" 8 9 "github.com/pkg/errors" 10 ) 11 12 func installDir() (string, error) { 13 homeDir, found := os.LookupEnv("OYA_HOME") 14 if !found { 15 user, err := user.Current() 16 if err != nil { 17 return "", err 18 } 19 20 if len(user.HomeDir) == 0 { 21 return "", errors.Errorf("Could not detect user home directory") 22 } 23 homeDir = user.HomeDir 24 } 25 26 return filepath.Join(homeDir, ".oya", "packs"), nil 27 } 28 29 func lookupOyaScope() (string, bool) { 30 return os.LookupEnv("OYA_SCOPE") 31 } 32 33 func setOyaScope(scope string) error { 34 return os.Setenv("OYA_SCOPE", scope) 35 } 36 37 func mustSetOyaScope(scope string) { 38 if err := setOyaScope(scope); err != nil { 39 log.Fatalf("Internal error when setting Oya scope: %v", err) 40 } 41 } 42 43 func lookupOyaCmd() (string, bool) { 44 return os.LookupEnv("OYA_CMD") 45 }