github.com/symfony-cli/symfony-cli@v0.0.0-20240514161054-ece2df437dfa/util/util.go (about) 1 /* 2 * Copyright (c) 2021-present Fabien Potencier <fabien@symfony.com> 3 * 4 * This file is part of Symfony CLI project 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Affero General Public License as 8 * published by the Free Software Foundation, either version 3 of the 9 * License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Affero General Public License for more details. 15 * 16 * You should have received a copy of the GNU Affero General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 package util 21 22 import ( 23 "os/user" 24 "path/filepath" 25 26 "github.com/mitchellh/go-homedir" 27 ) 28 29 func GetHomeDir() string { 30 return filepath.Join(getUserHomeDir(), ".symfony5") 31 } 32 33 func getUserHomeDir() string { 34 if InCloud() { 35 u, err := user.Current() 36 if err != nil { 37 return "/tmp" 38 } 39 return "/tmp/" + u.Username 40 } 41 42 if homeDir, err := homedir.Dir(); err == nil { 43 return homeDir 44 } 45 46 return "." 47 }