Revert "fix issue:#2358 Support for creating a project with specifying the name for its place dir (#2573)"

This reverts commit 3d322fe6c1.
pull/2577/head
baozhecheng 2 years ago
parent 3d322fe6c1
commit e36612e9ca
  1. 28
      cmd/kratos/internal/project/project.go

@ -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…
Cancel
Save