This commit is contained in:
anqiansong
2022-03-05 21:40:41 +08:00
committed by GitHub
parent b939ce75ba
commit 08a8bd7ef7
2 changed files with 47 additions and 4 deletions

View File

@@ -75,12 +75,23 @@ func FileNameWithoutExt(file string) string {
// GetGoctlHome returns the path value of the goctl, the default path is ~/.goctl, if the path has
// been set by calling the RegisterGoctlHome method, the user-defined path refers to.
func GetGoctlHome() (string, error) {
func GetGoctlHome() (home string, err error) {
defer func() {
if err != nil {
return
}
info, err := os.Stat(home)
if err == nil && !info.IsDir() {
os.Rename(home, home+".old")
MkdirIfNotExist(home)
}
}()
if len(goctlHome) != 0 {
return goctlHome, nil
home = goctlHome
return
}
return GetDefaultGoctlHome()
home, err = GetDefaultGoctlHome()
return
}
// GetDefaultGoctlHome returns the path value of the goctl home where Join $HOME with .goctl.