* fix issue #831

* fix typo

Co-authored-by: anqiansong <anqiansong@xiaoheiban.cn>
This commit is contained in:
anqiansong
2021-07-28 16:32:15 +08:00
committed by GitHub
parent cb7b7cb72e
commit 9f4a882a1b
9 changed files with 152 additions and 6 deletions

View File

@@ -17,6 +17,12 @@ const (
goctlDir = ".goctl"
)
var goctlHome string
func RegisterGoctlHome(home string) {
goctlHome = home
}
// CreateIfNotExist creates a file if it is not exists
func CreateIfNotExist(file string) (*os.File, error) {
_, err := os.Stat(file)
@@ -62,6 +68,10 @@ func FileNameWithoutExt(file string) string {
// GetGoctlHome returns the path value of the goctl home where Join $HOME with .goctl
func GetGoctlHome() (string, error) {
if len(goctlHome) != 0 {
return goctlHome, nil
}
home, err := os.UserHomeDir()
if err != nil {
return "", err