1
0
mirror of https://github.com/beego/bee.git synced 2024-12-22 04:50:49 +00:00

1. default gopath=false,

2. fix error work path.
This commit is contained in:
qiantao 2020-07-24 15:54:52 +08:00 committed by askuy
parent f601e441f3
commit dbb41fa430
4 changed files with 31 additions and 28 deletions

View File

@ -34,9 +34,10 @@ var CmdApiapp = &commands.Command{
Short: "Creates a Beego API application",
Long: `
The command 'api' creates a Beego API application.
now default supoort generate a go modules project.
{{"Example:"|bold}}
$ bee api [appname] [-tables=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"] [-module=true] [-beego=v1.12.1]
$ bee api [appname] [-tables=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"] [-gopath=false] [-beego=v1.12.1]
If 'conn' argument is empty, the command will generate an example API application. Otherwise the command
will connect to your database and generate models based on the existing tables.
@ -44,7 +45,7 @@ var CmdApiapp = &commands.Command{
The command 'api' creates a folder named [appname] with the following structure:
main.go
go.mod
go.mod
{{"conf"|foldername}}
app.conf
{{"controllers"|foldername}}
@ -543,15 +544,15 @@ func TestGet(t *testing.T) {
}
`
var module utils.DocValue
var gopath utils.DocValue
var beegoVersion utils.DocValue
func init() {
CmdApiapp.Flag.Var(&generate.Tables, "tables", "List of table names separated by a comma.")
CmdApiapp.Flag.Var(&generate.SQLDriver, "driver", "Database driver. Either mysql, postgres or sqlite.")
CmdApiapp.Flag.Var(&generate.SQLConn, "conn", "Connection string used by the driver to connect to a database instance.")
CmdApiapp.Flag.Var(&module, "module", "Support go modules")
CmdApiapp.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by -module=true")
CmdApiapp.Flag.Var(&gopath, "gopath", "Support go path,default false")
CmdApiapp.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by go mod")
commands.AvailableCommands = append(commands.AvailableCommands, CmdApiapp)
}
@ -563,14 +564,15 @@ func createAPI(cmd *commands.Command, args []string) int {
}
if len(args) >= 2 {
cmd.Flag.Parse(args[1:])
} else {
module = "false"
err := cmd.Flag.Parse(args[1:])
if err != nil {
beeLogger.Log.Fatal("Parse args err " + err.Error())
}
}
var appPath string
var packPath string
var err error
if module != `true` {
if gopath == `true` {
beeLogger.Log.Info("generate api project support GOPATH")
version.ShowShortVersionBanner()
appPath, packPath, err = utils.CheckEnv(args[0])
@ -605,7 +607,7 @@ func createAPI(cmd *commands.Command, args []string) int {
beeLogger.Log.Info("Creating API...")
os.MkdirAll(appPath, 0755)
if module == `true` { //generate first for calc model name
if gopath != `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, utils.GetGoVersionSkipMinor(), beegoVersion.String()))
}

View File

@ -24,7 +24,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"] [-module=true] [-beego=v1.12.1]
$ bee hprose [appname] [-tables=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"] [-gopath=false] [-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.
@ -52,15 +52,15 @@ require github.com/astaxie/beego %s
require github.com/smartystreets/goconvey v1.6.4
`
var module utils.DocValue
var gopath 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")
CmdHproseapp.Flag.Var(&gopath, "gopath", "Support go path,default false")
CmdHproseapp.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by go mod")
commands.AvailableCommands = append(commands.AvailableCommands, CmdHproseapp)
}
@ -71,15 +71,16 @@ func createhprose(cmd *commands.Command, args []string) int {
}
curpath, _ := os.Getwd()
if len(args) > 1 {
cmd.Flag.Parse(args[1:])
} else {
module = "false"
if len(args) >= 2 {
err := cmd.Flag.Parse(args[1:])
if err != nil {
beeLogger.Log.Fatal("Parse args err " + err.Error())
}
}
var apppath string
var packpath string
var err error
if module != `true` {
if gopath == `true` {
beeLogger.Log.Info("generate api project support GOPATH")
version.ShowShortVersionBanner()
apppath, packpath, err = utils.CheckEnv(args[0])
@ -109,7 +110,7 @@ func createhprose(cmd *commands.Command, args []string) int {
beeLogger.Log.Info("Creating Hprose application...")
os.MkdirAll(apppath, 0755)
if module == `true` { //generate first for calc model name
if gopath != `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, utils.GetGoVersionSkipMinor(), beegoVersion.String()))
}

View File

@ -31,12 +31,12 @@ var gopath utils.DocValue
var beegoVersion utils.DocValue
var CmdNew = &commands.Command{
UsageLine: "new [appname] [-module=true] [-beego=v1.12.1]",
UsageLine: "new [appname] [-gopath=false] [-beego=v1.12.1]",
Short: "Creates a Beego application",
Long: `
Creates a Beego application for the given app name in the current directory.
now supoort generate a go modules project
The command 'new' creates a folder named [appname] [-module=true] [-beego=v1.12.1] and generates the following structure:
now default supoort generate a go modules project
The command 'new' creates a folder named [appname] [-gopath=false] [-beego=v1.12.1] and generates the following structure:
main.go
go.mod
@ -255,8 +255,8 @@ var reloadJsClient = `function b(a){var c=new WebSocket(a);c.onclose=function(){
`
func init() {
CmdNew.Flag.Var(&gopath, "gopath", "Support go path")
CmdNew.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by module mod")
CmdNew.Flag.Var(&gopath, "gopath", "Support go path,default false")
CmdNew.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by go mod")
commands.AvailableCommands = append(commands.AvailableCommands, CmdNew)
}

View File

@ -34,11 +34,11 @@ import (
)
func GetBeeWorkPath() string {
beePath, err := filepath.Abs(filepath.Dir(os.Args[0]))
curpath, err := os.Getwd()
if err != nil {
panic(err)
}
return beePath
return curpath
}
// Go is a basic promise implementation: it wraps calls a function in a goroutine
@ -313,7 +313,7 @@ func Tmpl(text string, data interface{}) {
func CheckEnv(appname string) (apppath, packpath string, err error) {
gps := GetGOPATHs()
if len(gps) == 0 {
beeLogger.Log.Error("if you want new a go module project,please add param `-module=true` and set env `G111MODULE=on`")
beeLogger.Log.Error("if you want new a go module project,please add param `-gopath=false`.")
beeLogger.Log.Fatal("GOPATH environment variable is not set or empty")
}
currpath, _ := os.Getwd()