modelctl.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "github.com/tal-tech/go-zero/core/logx"
  6. configgen "github.com/tal-tech/go-zero/tools/modelctl/model/configtemplategen"
  7. "github.com/tal-tech/go-zero/tools/modelctl/model/modelgen"
  8. "github.com/urfave/cli"
  9. )
  10. var commands = []cli.Command{
  11. {
  12. Name: "model",
  13. Usage: "generate model files",
  14. Subcommands: []cli.Command{
  15. {
  16. Name: "template",
  17. Usage: "generate the json config template",
  18. Action: configgen.ConfigCommand,
  19. },
  20. {
  21. Name: "file",
  22. Usage: "generated from a configuration file",
  23. Action: modelgen.FileModelCommand,
  24. Flags: []cli.Flag{
  25. cli.StringFlag{
  26. Name: "config,c",
  27. Usage: "the file path of config",
  28. },
  29. },
  30. },
  31. {
  32. Name: "cmd",
  33. Usage: "generated from the command line,it will be generated from ALL TABLES",
  34. Action: modelgen.CmdModelCommand,
  35. Flags: []cli.Flag{
  36. cli.StringFlag{
  37. Name: "address,a",
  38. Usage: "database connection address,format:\"[username]:[password]@[address]\"",
  39. },
  40. cli.StringFlag{
  41. Name: "schema,s",
  42. Usage: "the target database name",
  43. },
  44. cli.BoolFlag{
  45. Name: "force,f",
  46. Usage: "whether to force the generation, if it is, it may cause the source file to be lost,[default:false]",
  47. },
  48. cli.BoolFlag{
  49. Name: "redis,r",
  50. Usage: "whether to generate with redis cache when generating files,[default:false]",
  51. },
  52. },
  53. },
  54. },
  55. },
  56. }
  57. func main() {
  58. logx.Disable()
  59. app := cli.NewApp()
  60. app.Usage = "a cli tool to generate model"
  61. app.Version = "0.0.1"
  62. app.Commands = commands
  63. // cli already print error messages
  64. if err := app.Run(os.Args); err != nil {
  65. fmt.Println("error:", err)
  66. }
  67. }