install.go 809 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package cmd
  2. import (
  3. "fmt"
  4. "github.com/spf13/cobra"
  5. "github.com/wenstudio/gofly/config"
  6. "github.com/wenstudio/gofly/models"
  7. "github.com/wenstudio/gofly/tools"
  8. "io/ioutil"
  9. "os"
  10. "strings"
  11. )
  12. var installCmd = &cobra.Command{
  13. Use: "install",
  14. Short: "example:gofly install",
  15. Run: func(cmd *cobra.Command, args []string) {
  16. install()
  17. },
  18. }
  19. func install() {
  20. sqlFile := config.Dir + "go-fly.sql"
  21. isExit, _ := tools.IsFileExist(config.MysqlConf)
  22. dataExit, _ := tools.IsFileExist(sqlFile)
  23. if !isExit || !dataExit {
  24. fmt.Println("config/mysql.json 数据库配置文件或者数据库文件go-fly.sql不存在")
  25. os.Exit(1)
  26. }
  27. sqls, _ := ioutil.ReadFile(sqlFile)
  28. sqlArr := strings.Split(string(sqls), "|")
  29. for _, sql := range sqlArr {
  30. if sql == "" {
  31. continue
  32. }
  33. models.Execute(sql)
  34. }
  35. }