fix: module name replace

pull/2898/head
twacqwq 2 years ago
parent 7934811009
commit 0a037289e2
  1. 6
      cmd/kratos/internal/base/mod.go
  2. 17
      cmd/kratos/internal/project/new.go
  3. 3
      cmd/kratos/internal/project/project.go

@ -62,7 +62,11 @@ func KratosMod() string {
}
// ModuleName returns custom module name
func ModuleName(moduleFile, moduleName string) error {
func ModuleName(moduleFile, moduleName, name string) error {
if moduleName == "" || moduleName == name {
return nil
}
modBytes, err := os.ReadFile(moduleFile)
if err != nil {
return err

@ -39,7 +39,7 @@ func (p *Project) New(ctx context.Context, dir string, layout string, branch str
}
os.RemoveAll(to)
}
fmt.Printf("🚀 Creating service %s, layout repo is %s, module name is %s, please wait a moment.\n\n", p.Name, layout, p.ModuleName)
fmt.Printf("🚀 Creating service %s, layout repo is %s, please wait a moment.\n\n", p.Name, layout)
repo := base.NewRepo(layout, branch)
if err := repo.CopyTo(ctx, to, p.Name, []string{".git", ".github"}); err != nil {
return err
@ -51,15 +51,20 @@ func (p *Project) New(ctx context.Context, dir string, layout string, branch str
if e != nil {
return e
}
if p.ModuleName != "" && p.ModuleName != p.Name {
e = base.ModuleName(path.Join(to, "go.mod"), p.ModuleName)
if e != nil {
return e
}
e = base.ModuleName(
path.Join(to, "go.mod"),
p.ModuleName,
p.Name,
)
if e != nil {
return e
}
base.Tree(to, dir)
fmt.Printf("\n🍺 Project creation succeeded %s\n", color.GreenString(p.Name))
if p.ModuleName != "" {
fmt.Printf("👉 Module name replace succeeded %s\n", color.BlueString(p.ModuleName))
}
fmt.Print("💻 Use the following command to start the project 👇:\n\n")
fmt.Println(color.WhiteString("$ cd %s", p.Name))

@ -66,9 +66,6 @@ func run(_ *cobra.Command, args []string) {
}
} else {
name = args[0]
if moduleName == "" {
moduleName = name
}
}
projectName, workingDir := processProjectParams(name, wd)
p := &Project{Name: projectName, ModuleName: moduleName}

Loading…
Cancel
Save