mirror of
https://github.com/beego/bee.git
synced 2025-06-12 04:50:40 +00:00
1. new,api,hprose 命令增加两个参数 [-module=true] [-beego=v1.12.1] 用于生成go module项目
2. generate,migrate命令不再打印GOPATH. 3. pack命令排除。 4. run命令支持传递ldflags参数 5. fix watch file bug.ignoredFilesRegExps数组对每个文件增加$,防止目录存在tmp的情况 6. getPackagePath函数被调用时如果找不到GOPATH,则看看工程有没有go.mod 有就当做go module项目处理。 7. .travis.yml检查时排除/pkg/mod/目录
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
package hprose
|
||||
|
||||
import (
|
||||
"github.com/beego/bee/logger/colors"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"fmt"
|
||||
"path"
|
||||
@ -24,7 +26,7 @@ var CmdHproseapp = &commands.Command{
|
||||
|
||||
{{"To scaffold out your application, use:"|bold}}
|
||||
|
||||
$ bee hprose [appname] [-tables=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"]
|
||||
$ bee hprose [appname] [-tables=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"] [-module=true] [-beego=v1.12.1]
|
||||
|
||||
If 'conn' is empty, the command will generate a sample application. Otherwise the command
|
||||
will connect to your database and generate models based on the existing tables.
|
||||
@ -32,6 +34,7 @@ var CmdHproseapp = &commands.Command{
|
||||
The command 'hprose' creates a folder named [appname] with the following structure:
|
||||
|
||||
├── main.go
|
||||
├── go.mod
|
||||
├── {{"conf"|foldername}}
|
||||
│ └── app.conf
|
||||
└── {{"models"|foldername}}
|
||||
@ -42,34 +45,76 @@ var CmdHproseapp = &commands.Command{
|
||||
Run: createhprose,
|
||||
}
|
||||
|
||||
var goMod = `
|
||||
module %s
|
||||
|
||||
go %s
|
||||
|
||||
require github.com/astaxie/beego %s
|
||||
require github.com/smartystreets/goconvey v1.6.4
|
||||
`
|
||||
|
||||
var module utils.DocValue
|
||||
var beegoVersion utils.DocValue
|
||||
|
||||
func init() {
|
||||
CmdHproseapp.Flag.Var(&generate.Tables, "tables", "List of table names separated by a comma.")
|
||||
CmdHproseapp.Flag.Var(&generate.SQLDriver, "driver", "Database driver. Either mysql, postgres or sqlite.")
|
||||
CmdHproseapp.Flag.Var(&generate.SQLConn, "conn", "Connection string used by the driver to connect to a database instance.")
|
||||
CmdHproseapp.Flag.Var(&module, "module", "Support go modules")
|
||||
CmdHproseapp.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by -module=true")
|
||||
commands.AvailableCommands = append(commands.AvailableCommands, CmdHproseapp)
|
||||
}
|
||||
|
||||
func createhprose(cmd *commands.Command, args []string) int {
|
||||
output := cmd.Out()
|
||||
|
||||
if len(args) != 1 {
|
||||
if len(args) == 0 {
|
||||
beeLogger.Log.Fatal("Argument [appname] is missing")
|
||||
}
|
||||
|
||||
curpath, _ := os.Getwd()
|
||||
if len(args) > 1 {
|
||||
cmd.Flag.Parse(args[1:])
|
||||
} else {
|
||||
module = "false"
|
||||
}
|
||||
apppath, packpath, err := utils.CheckEnv(args[0])
|
||||
if err != nil {
|
||||
beeLogger.Log.Fatalf("%s", err)
|
||||
var apppath string
|
||||
var packpath string
|
||||
var err error
|
||||
if module != `true` {
|
||||
beeLogger.Log.Info("generate api project support GOPATH")
|
||||
version.ShowShortVersionBanner()
|
||||
apppath, packpath, err = utils.CheckEnv(args[0])
|
||||
if err != nil {
|
||||
beeLogger.Log.Fatalf("%s", err)
|
||||
}
|
||||
} else {
|
||||
beeLogger.Log.Info("generate api project support go modules.")
|
||||
apppath = path.Join(utils.GetBeeWorkPath(), args[0])
|
||||
packpath = args[0]
|
||||
if beegoVersion.String() == `` {
|
||||
beegoVersion.Set(`v1.12.1`)
|
||||
}
|
||||
}
|
||||
|
||||
if utils.IsExist(apppath) {
|
||||
beeLogger.Log.Errorf(colors.Bold("Application '%s' already exists"), apppath)
|
||||
beeLogger.Log.Warn(colors.Bold("Do you want to overwrite it? [Yes|No] "))
|
||||
if !utils.AskForConfirmation() {
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
|
||||
if generate.SQLDriver == "" {
|
||||
generate.SQLDriver = "mysql"
|
||||
}
|
||||
beeLogger.Log.Info("Creating Hprose application...")
|
||||
|
||||
os.MkdirAll(apppath, 0755)
|
||||
if module == `true` { //generate first for calc model name
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "go.mod"), "\x1b[0m")
|
||||
utils.WriteToFile(path.Join(apppath, "go.mod"), fmt.Sprintf(goMod, packpath, runtime.Version()[2:], beegoVersion.String()))
|
||||
}
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", apppath, "\x1b[0m")
|
||||
os.Mkdir(path.Join(apppath, "conf"), 0755)
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "conf"), "\x1b[0m")
|
||||
|
Reference in New Issue
Block a user