mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-27 21:49:08 +02:00
Revert "fix issue:#2358 Support for creating a project with specifying the name for its place dir (#2573)"
This reverts commit 3d322fe6c13a9e021199ae7261b7adcadac71316.
This commit is contained in:
parent
3d322fe6c1
commit
e36612e9ca
@ -6,8 +6,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
@ -66,8 +64,7 @@ func run(cmd *cobra.Command, args []string) {
|
||||
} else {
|
||||
name = args[0]
|
||||
}
|
||||
wd = getProjectPlaceDir(name, wd)
|
||||
p := &Project{Name: filepath.Base(name), Path: name}
|
||||
p := &Project{Name: path.Base(name), Path: name}
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
if !nomod {
|
||||
@ -98,26 +95,3 @@ func run(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getProjectPlaceDir(projectName string, fallbackPlaceDir string) string {
|
||||
projectWorkingDir := filepath.Dir(projectName)
|
||||
// check for home dir
|
||||
if strings.HasPrefix(projectWorkingDir, "~") {
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
// cannot get user home return fallback place dir
|
||||
return fallbackPlaceDir
|
||||
}
|
||||
projectName = filepath.Join(homeDir, projectName[2:])
|
||||
}
|
||||
// check path is relative
|
||||
if !filepath.IsAbs(projectWorkingDir) {
|
||||
wdAbs, err := filepath.Abs(projectName)
|
||||
if err != nil {
|
||||
return fallbackPlaceDir
|
||||
}
|
||||
projectWorkingDir = wdAbs
|
||||
}
|
||||
// create project logic will check stat,so not check path stat here
|
||||
return projectWorkingDir
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user