feat(goctl): Support gateway sample generation (#3049)
This commit is contained in:
@@ -1,55 +1,27 @@
|
||||
package tpl
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
import "github.com/zeromicro/go-zero/tools/goctl/internal/cobrax"
|
||||
|
||||
var (
|
||||
varStringHome string
|
||||
varStringCategory string
|
||||
varStringName string
|
||||
// Cmd describes a template command.
|
||||
Cmd = &cobra.Command{
|
||||
Use: "template",
|
||||
Short: "Template operation",
|
||||
}
|
||||
|
||||
initCmd = &cobra.Command{
|
||||
Use: "init",
|
||||
Short: "Initialize the all templates(force update)",
|
||||
RunE: genTemplates,
|
||||
}
|
||||
|
||||
cleanCmd = &cobra.Command{
|
||||
Use: "clean",
|
||||
Short: "Clean the all cache templates",
|
||||
RunE: cleanTemplates,
|
||||
}
|
||||
|
||||
updateCmd = &cobra.Command{
|
||||
Use: "update",
|
||||
Short: "Update template of the target category to the latest",
|
||||
RunE: updateTemplates,
|
||||
}
|
||||
|
||||
revertCmd = &cobra.Command{
|
||||
Use: "revert",
|
||||
Short: "Revert the target template to the latest",
|
||||
RunE: revertTemplates,
|
||||
}
|
||||
Cmd = cobrax.NewCommand("template")
|
||||
initCmd = cobrax.NewCommand("init", cobrax.WithRunE(genTemplates))
|
||||
cleanCmd = cobrax.NewCommand("clean", cobrax.WithRunE(cleanTemplates))
|
||||
updateCmd = cobrax.NewCommand("update", cobrax.WithRunE(updateTemplates))
|
||||
revertCmd = cobrax.NewCommand("revert", cobrax.WithRunE(revertTemplates))
|
||||
)
|
||||
|
||||
func init() {
|
||||
initCmd.Flags().StringVar(&varStringHome, "home", "", "The goctl home path of the template")
|
||||
cleanCmd.Flags().StringVar(&varStringHome, "home", "", "The goctl home path of the template")
|
||||
updateCmd.Flags().StringVar(&varStringHome, "home", "", "The goctl home path of the template")
|
||||
updateCmd.Flags().StringVarP(&varStringCategory, "category", "c", "", "The category of template, enum [api,rpc,model,docker,kube]")
|
||||
revertCmd.Flags().StringVar(&varStringHome, "home", "", "The goctl home path of the template")
|
||||
revertCmd.Flags().StringVarP(&varStringCategory, "category", "c", "", "The category of template, enum [api,rpc,model,docker,kube]")
|
||||
revertCmd.Flags().StringVarP(&varStringName, "name", "n", "", "The target file name of template")
|
||||
initCmd.Flags().StringVar(&varStringHome, "home")
|
||||
cleanCmd.Flags().StringVar(&varStringHome, "home")
|
||||
updateCmd.Flags().StringVar(&varStringHome, "home")
|
||||
updateCmd.Flags().StringVarP(&varStringCategory, "category", "c")
|
||||
revertCmd.Flags().StringVar(&varStringHome, "home")
|
||||
revertCmd.Flags().StringVarP(&varStringCategory, "category", "c")
|
||||
revertCmd.Flags().StringVarP(&varStringName, "name", "n")
|
||||
|
||||
Cmd.AddCommand(cleanCmd)
|
||||
Cmd.AddCommand(initCmd)
|
||||
Cmd.AddCommand(revertCmd)
|
||||
Cmd.AddCommand(updateCmd)
|
||||
Cmd.AddCommand(cleanCmd, initCmd, revertCmd, updateCmd)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/tools/goctl/api/gogen"
|
||||
apinew "github.com/zeromicro/go-zero/tools/goctl/api/new"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/docker"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/gateway"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/kube"
|
||||
mongogen "github.com/zeromicro/go-zero/tools/goctl/model/mongo/generate"
|
||||
modelgen "github.com/zeromicro/go-zero/tools/goctl/model/sql/gen"
|
||||
@@ -52,6 +53,9 @@ func genTemplates(_ *cobra.Command, _ []string) error {
|
||||
func() error {
|
||||
return apinew.GenTemplates()
|
||||
},
|
||||
func() error {
|
||||
return gateway.GenTemplates()
|
||||
},
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -104,6 +108,9 @@ func cleanTemplates(_ *cobra.Command, _ []string) error {
|
||||
func() error {
|
||||
return apinew.Clean()
|
||||
},
|
||||
func() error {
|
||||
return gateway.Clean()
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -144,6 +151,8 @@ func updateTemplates(_ *cobra.Command, _ []string) (err error) {
|
||||
return apigen.Update()
|
||||
case apinew.Category():
|
||||
return apinew.Update()
|
||||
case gateway.Category():
|
||||
return gateway.Update()
|
||||
default:
|
||||
err = fmt.Errorf("unexpected category: %s", category)
|
||||
return
|
||||
@@ -181,6 +190,8 @@ func revertTemplates(_ *cobra.Command, _ []string) (err error) {
|
||||
return apigen.RevertTemplate(filename)
|
||||
case apinew.Category():
|
||||
return apinew.RevertTemplate(filename)
|
||||
case gateway.Category():
|
||||
return gateway.RevertTemplate(filename)
|
||||
default:
|
||||
err = fmt.Errorf("unexpected category: %s", category)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user