cmd.go 6.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package model
  2. import (
  3. "github.com/spf13/cobra"
  4. "github.com/zeromicro/go-zero/tools/goctl/model/mongo"
  5. "github.com/zeromicro/go-zero/tools/goctl/model/sql/command"
  6. )
  7. var (
  8. // Cmd describes a model command.
  9. Cmd = &cobra.Command{
  10. Use: "model",
  11. Short: "Generate model code",
  12. }
  13. mysqlCmd = &cobra.Command{
  14. Use: "mysql",
  15. Short: "Generate mysql model",
  16. }
  17. ddlCmd = &cobra.Command{
  18. Use: "ddl",
  19. Short: "Generate mysql model from ddl",
  20. RunE: command.MysqlDDL,
  21. }
  22. datasourceCmd = &cobra.Command{
  23. Use: "datasource",
  24. Short: "Generate model from datasource",
  25. RunE: command.MySqlDataSource,
  26. }
  27. pgCmd = &cobra.Command{
  28. Use: "pg",
  29. Short: "Generate postgresql model",
  30. RunE: command.PostgreSqlDataSource,
  31. }
  32. mongoCmd = &cobra.Command{
  33. Use: "mongo",
  34. Short: "Generate mongo model",
  35. RunE: mongo.Action,
  36. }
  37. )
  38. func init() {
  39. ddlCmd.Flags().StringVarP(&command.VarStringSrc, "src", "s", "", "The path or path globbing patterns of the ddl")
  40. ddlCmd.Flags().StringVarP(&command.VarStringDir, "dir", "d", "", "The target dir")
  41. ddlCmd.Flags().StringVar(&command.VarStringStyle, "style", "", "The file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]")
  42. ddlCmd.Flags().BoolVarP(&command.VarBoolCache, "cache", "c", false, "Generate code with cache [optional]")
  43. ddlCmd.Flags().BoolVar(&command.VarBoolIdea, "idea", false, "For idea plugin [optional]")
  44. ddlCmd.Flags().StringVar(&command.VarStringDatabase, "database", "", "The name of database [optional]")
  45. ddlCmd.Flags().StringVar(&command.VarStringHome, "home", "", "The goctl home path of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority")
  46. ddlCmd.Flags().StringVar(&command.VarStringRemote, "remote", "", "The remote git repo of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure")
  47. ddlCmd.Flags().StringVar(&command.VarStringBranch, "branch", "", "The branch of the remote repo, it does work with --remote")
  48. datasourceCmd.Flags().StringVar(&command.VarStringURL, "url", "", `The data source of database,like "root:password@tcp(127.0.0.1:3306)/database"`)
  49. datasourceCmd.Flags().StringSliceVarP(&command.VarStringSliceTable, "table", "t", nil, "The table or table globbing patterns in the database")
  50. datasourceCmd.Flags().BoolVarP(&command.VarBoolCache, "cache", "c", false, "Generate code with cache [optional]")
  51. datasourceCmd.Flags().StringVarP(&command.VarStringDir, "dir", "d", "", "The target dir")
  52. datasourceCmd.Flags().StringVar(&command.VarStringStyle, "style", "", "The file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]")
  53. datasourceCmd.Flags().BoolVar(&command.VarBoolIdea, "idea", false, "For idea plugin [optional]")
  54. datasourceCmd.Flags().StringVar(&command.VarStringHome, "home", "", "The goctl home path of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority")
  55. datasourceCmd.Flags().StringVar(&command.VarStringRemote, "remote", "", "The remote git repo of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure")
  56. datasourceCmd.Flags().StringVar(&command.VarStringBranch, "branch", "", "The branch of the remote repo, it does work with --remote")
  57. pgCmd.Flags().StringVar(&command.VarStringURL, "url", "", `The data source of database,like "root:password@tcp(127.0.0.1:3306)/database"`)
  58. pgCmd.Flags().StringVarP(&command.VarStringTable, "table", "t", "", "The table or table globbing patterns in the database")
  59. pgCmd.Flags().StringVarP(&command.VarStringSchema, "schema", "s", "public", "The table schema")
  60. pgCmd.Flags().BoolVarP(&command.VarBoolCache, "cache", "c", false, "Generate code with cache [optional]")
  61. pgCmd.Flags().StringVarP(&command.VarStringDir, "dir", "d", "", "The target dir")
  62. pgCmd.Flags().StringVar(&command.VarStringStyle, "style", "", "The file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]")
  63. pgCmd.Flags().BoolVar(&command.VarBoolIdea, "idea", false, "For idea plugin [optional]")
  64. pgCmd.Flags().StringVar(&command.VarStringHome, "home", "", "The goctl home path of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority")
  65. pgCmd.Flags().StringVar(&command.VarStringRemote, "remote", "", "The remote git repo of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure")
  66. pgCmd.Flags().StringVar(&command.VarStringBranch, "branch", "", "The branch of the remote repo, it does work with --remote")
  67. mongoCmd.Flags().StringSliceVarP(&mongo.VarStringSliceType, "type", "t", nil, "Specified model type name")
  68. mongoCmd.Flags().BoolVarP(&mongo.VarBoolCache, "cache", "c", false, "Generate code with cache [optional]")
  69. mongoCmd.Flags().StringVarP(&mongo.VarStringDir, "dir", "d", "", "The target dir")
  70. mongoCmd.Flags().StringVar(&mongo.VarStringStyle, "style", "", "The file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]")
  71. mongoCmd.Flags().StringVar(&mongo.VarStringHome, "home", "", "The goctl home path of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority")
  72. mongoCmd.Flags().StringVar(&mongo.VarStringRemote, "remote", "", "The remote git repo of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure")
  73. mongoCmd.Flags().StringVar(&mongo.VarStringBranch, "branch", "", "The branch of the remote repo, it does work with --remote")
  74. mysqlCmd.AddCommand(datasourceCmd)
  75. mysqlCmd.AddCommand(ddlCmd)
  76. mysqlCmd.AddCommand(pgCmd)
  77. Cmd.AddCommand(mysqlCmd)
  78. Cmd.AddCommand(mongoCmd)
  79. }