123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- package tpl
- import (
- "fmt"
- "git.i2edu.net/i2/go-zero/core/errorx"
- "git.i2edu.net/i2/go-zero/tools/goctl/api/gogen"
- "git.i2edu.net/i2/go-zero/tools/goctl/docker"
- "git.i2edu.net/i2/go-zero/tools/goctl/kube"
- mongogen "git.i2edu.net/i2/go-zero/tools/goctl/model/mongo/generate"
- modelgen "git.i2edu.net/i2/go-zero/tools/goctl/model/sql/gen"
- rpcgen "git.i2edu.net/i2/go-zero/tools/goctl/rpc/generator"
- "git.i2edu.net/i2/go-zero/tools/goctl/util"
- "github.com/logrusorgru/aurora"
- "github.com/urfave/cli"
- )
- const templateParentPath = "/"
- func GenTemplates(ctx *cli.Context) error {
- if err := errorx.Chain(
- func() error {
- return gogen.GenTemplates(ctx)
- },
- func() error {
- return modelgen.GenTemplates(ctx)
- },
- func() error {
- return rpcgen.GenTemplates(ctx)
- },
- func() error {
- return docker.GenTemplates(ctx)
- },
- func() error {
- return kube.GenTemplates(ctx)
- },
- func() error {
- return mongogen.Templates(ctx)
- },
- ); err != nil {
- return err
- }
- dir, err := util.GetTemplateDir(templateParentPath)
- if err != nil {
- return err
- }
- fmt.Printf("Templates are generated in %s, %s\n", aurora.Green(dir),
- aurora.Red("edit on your risk!"))
- return nil
- }
- func CleanTemplates(_ *cli.Context) error {
- err := errorx.Chain(
- func() error {
- return gogen.Clean()
- },
- func() error {
- return modelgen.Clean()
- },
- func() error {
- return rpcgen.Clean()
- },
- func() error {
- return docker.Clean()
- },
- func() error {
- return kube.Clean()
- },
- func() error {
- return mongogen.Clean()
- },
- )
- if err != nil {
- return err
- }
- fmt.Printf("%s\n", aurora.Green("template are clean!"))
- return nil
- }
- func UpdateTemplates(ctx *cli.Context) (err error) {
- category := ctx.String("category")
- defer func() {
- if err == nil {
- fmt.Println(aurora.Green(fmt.Sprintf("%s template are update!", category)).String())
- }
- }()
- switch category {
- case docker.Category():
- return docker.Update()
- case gogen.Category():
- return gogen.Update()
- case kube.Category():
- return kube.Update()
- case rpcgen.Category():
- return rpcgen.Update()
- case modelgen.Category():
- return modelgen.Update()
- case mongogen.Category():
- return mongogen.Update()
- default:
- err = fmt.Errorf("unexpected category: %s", category)
- return
- }
- }
- func RevertTemplates(ctx *cli.Context) (err error) {
- category := ctx.String("category")
- filename := ctx.String("name")
- defer func() {
- if err == nil {
- fmt.Println(aurora.Green(fmt.Sprintf("%s template are reverted!", filename)).String())
- }
- }()
- switch category {
- case docker.Category():
- return docker.RevertTemplate(filename)
- case kube.Category():
- return kube.RevertTemplate(filename)
- case gogen.Category():
- return gogen.RevertTemplate(filename)
- case rpcgen.Category():
- return rpcgen.RevertTemplate(filename)
- case modelgen.Category():
- return modelgen.RevertTemplate(filename)
- case mongogen.Category():
- return mongogen.RevertTemplate(filename)
- default:
- err = fmt.Errorf("unexpected category: %s", category)
- return
- }
- }
|