You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.1 KiB

4 years ago
  1. /*
  2. Copyright © 2020 SliverHorn
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package gva
  14. import (
  15. "gin-vue-admin/cmd/datas"
  16. "gin-vue-admin/core"
  17. "gin-vue-admin/initialize"
  18. "github.com/gookit/color"
  19. _ "gin-vue-admin/core"
  20. "gin-vue-admin/global"
  21. "github.com/spf13/cobra"
  22. )
  23. // initdbCmd represents the initdb command
  24. var initdbCmd = &cobra.Command{
  25. Use: "initdb",
  26. Short: "gin-vue-admin初始化数据",
  27. Long: `gin-vue-admin初始化数据适配数据库情况:
  28. 1. mysql完美适配,
  29. 2. postgresql不能保证完美适配,
  30. 3. sqlite未适配,
  31. 4. sqlserver未适配`,
  32. Run: func(cmd *cobra.Command, args []string) {
  33. path, _ := cmd.Flags().GetString("path")
  34. global.GVA_VP = core.Viper(path)
  35. global.GVA_LOG = core.Zap() // 初始化zap日志库
  36. db := initialize.GormMysql()
  37. switch global.GVA_CONFIG.System.DbType {
  38. case "mysql":
  39. datas.InitMysqlTables(db)
  40. datas.InitMysqlData(db)
  41. case "postgresql":
  42. color.Info.Println("postgresql功能开发中")
  43. case "sqlite":
  44. color.Info.Println("sqlite功能开发中")
  45. case "sqlserver":
  46. color.Info.Println("sqlserver功能开发中")
  47. default:
  48. datas.InitMysqlTables(db)
  49. datas.InitMysqlData(db)
  50. }
  51. frame, _ := cmd.Flags().GetString("frame")
  52. if frame == "gf" {
  53. color.Info.Println("gf功能开发中")
  54. return
  55. } else {
  56. return
  57. }
  58. },
  59. }
  60. func init() {
  61. rootCmd.AddCommand(initdbCmd)
  62. initdbCmd.Flags().StringP("path", "p", "./config.yaml", "自定配置文件路径(绝对路径)")
  63. initdbCmd.Flags().StringP("frame", "f", "gin", "可选参数为gin,gf")
  64. initdbCmd.Flags().StringP("type", "t", "mysql", "可选参数为mysql,postgresql,sqlite,sqlserver")
  65. }