1
0
mirror of https://github.com/beego/bee.git synced 2024-11-25 15:00:55 +00:00

add command "bee pro toml" for create beegopro.toml

This commit is contained in:
wangle 2020-09-10 19:35:44 +08:00
parent 8b942b1f22
commit 8f0badc630
2 changed files with 28 additions and 6 deletions

View File

@ -47,6 +47,8 @@ func BeegoPro(cmd *commands.Command, args []string) int {
switch gcmd { switch gcmd {
case "gen": case "gen":
beegopro.DefaultBeegoPro.Run() beegopro.DefaultBeegoPro.Run()
case "toml":
beegopro.DefaultBeegoPro.InitToml()
case "config": case "config":
beegopro.DefaultBeegoPro.GenConfig() beegopro.DefaultBeegoPro.GenConfig()
case "migration": case "migration":

View File

@ -2,16 +2,18 @@ package beegopro
import ( import (
"fmt" "fmt"
"io/ioutil"
"sync"
"time"
"github.com/davecgh/go-spew/spew"
"github.com/pelletier/go-toml"
"github.com/spf13/viper"
"github.com/beego/bee/internal/pkg/git" "github.com/beego/bee/internal/pkg/git"
"github.com/beego/bee/internal/pkg/system" "github.com/beego/bee/internal/pkg/system"
beeLogger "github.com/beego/bee/logger" beeLogger "github.com/beego/bee/logger"
"github.com/beego/bee/utils" "github.com/beego/bee/utils"
"github.com/davecgh/go-spew/spew"
"github.com/pelletier/go-toml"
"github.com/spf13/viper"
"io/ioutil"
"sync"
"time"
) )
const MDateFormat = "20060102_150405" const MDateFormat = "20060102_150405"
@ -60,6 +62,24 @@ func (c *Container) Run() {
c.flushTimestamp() c.flushTimestamp()
} }
func (c *Container) InitToml() {
if exist := utils.IsExist(c.BeegoProFile); exist {
beeLogger.Log.Fatalf("file beegopro.toml already exists")
}
sourceFile := c.UserOption.GitLocalPath + "/beegopro.toml"
input, err := ioutil.ReadFile(sourceFile)
if err != nil {
beeLogger.Log.Fatalf("read beegopro.toml file err, %s", err.Error())
return
}
err = ioutil.WriteFile(c.BeegoProFile, input, 0644)
if err != nil {
beeLogger.Log.Fatalf("create beegopro.toml file err, %s", err.Error())
return
}
beeLogger.Log.Success("Successfully created file beegopro.toml")
}
func (c *Container) initUserOption() { func (c *Container) initUserOption() {
if !utils.IsExist(c.BeegoProFile) { if !utils.IsExist(c.BeegoProFile) {
beeLogger.Log.Fatalf("beego pro config is not exist, beego json path: %s", c.BeegoProFile) beeLogger.Log.Fatalf("beego pro config is not exist, beego json path: %s", c.BeegoProFile)