feat: 命令行创建模型

main
熊二 1 year ago
parent a8d03f5a8f
commit 95ed5bbdd4
  1. 11
      cmd/commands/create_entity.go
  2. 16
      scripts/gen/gen.go

@ -0,0 +1,11 @@
package commands
import (
"github.com/urfave/cli/v2"
)
func CreateEntity(c *cli.Context) error {
args := c.Args()
args.Get(0)
}

@ -55,10 +55,9 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
os.MkdirAll("../internal/repositories", os.ModePerm) _ = os.MkdirAll("../internal/repositories", os.ModePerm)
var camels []string var camels []string
var pascals []string var pascals []string
var iocStr string
var createdCount int var createdCount int
for _, dir := range dirs { for _, dir := range dirs {
name := dir.Name() name := dir.Name()
@ -79,7 +78,6 @@ func main() {
fmt.Println("跳过 " + dir.Name()) fmt.Println("跳过 " + dir.Name())
continue continue
} }
iocStr += "\tioc.MustSingleton(New" + pascal + "Repository)\n"
repository := "../internal/repositories/" + dir.Name() repository := "../internal/repositories/" + dir.Name()
if PathExists(repository) { if PathExists(repository) {
fmt.Println("跳过 " + dir.Name()) fmt.Println("跳过 " + dir.Name())
@ -87,21 +85,11 @@ func main() {
code := strings.ReplaceAll(repoStub, "{{pascal}}", pascal) code := strings.ReplaceAll(repoStub, "{{pascal}}", pascal)
code = strings.ReplaceAll(code, "{{camel}}", camel) code = strings.ReplaceAll(code, "{{camel}}", camel)
code = strings.ReplaceAll(code, "{{label}}", label) code = strings.ReplaceAll(code, "{{label}}", label)
os.WriteFile("../internal/repositories/"+dir.Name(), []byte(code), os.ModePerm) _ = os.WriteFile("../internal/repositories/"+dir.Name(), []byte(code), os.ModePerm)
fmt.Println("创建 " + dir.Name()) fmt.Println("创建 " + dir.Name())
createdCount++ createdCount++
} }
} }
if createdCount > 0 {
os.WriteFile("../internal/repositories/ioc.go", []byte(`package repositories
import "sorbet/pkg/ioc"
func init() {
`+iocStr+`}
`), os.ModePerm)
}
} }
func PathExists(path string) bool { func PathExists(path string) bool {

Loading…
Cancel
Save