mirror of
https://github.com/beego/bee.git
synced 2024-11-22 10:10:53 +00:00
1. default gopath=false,
2. fix error work path.
This commit is contained in:
parent
f601e441f3
commit
dbb41fa430
@ -34,9 +34,10 @@ var CmdApiapp = &commands.Command{
|
|||||||
Short: "Creates a Beego API application",
|
Short: "Creates a Beego API application",
|
||||||
Long: `
|
Long: `
|
||||||
The command 'api' creates a Beego API application.
|
The command 'api' creates a Beego API application.
|
||||||
|
now default supoort generate a go modules project.
|
||||||
|
|
||||||
{{"Example:"|bold}}
|
{{"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
|
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.
|
will connect to your database and generate models based on the existing tables.
|
||||||
@ -543,15 +544,15 @@ func TestGet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
`
|
`
|
||||||
var module utils.DocValue
|
var gopath utils.DocValue
|
||||||
var beegoVersion utils.DocValue
|
var beegoVersion utils.DocValue
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
CmdApiapp.Flag.Var(&generate.Tables, "tables", "List of table names separated by a comma.")
|
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.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(&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(&gopath, "gopath", "Support go path,default false")
|
||||||
CmdApiapp.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by -module=true")
|
CmdApiapp.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by go mod")
|
||||||
commands.AvailableCommands = append(commands.AvailableCommands, CmdApiapp)
|
commands.AvailableCommands = append(commands.AvailableCommands, CmdApiapp)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,14 +564,15 @@ func createAPI(cmd *commands.Command, args []string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(args) >= 2 {
|
if len(args) >= 2 {
|
||||||
cmd.Flag.Parse(args[1:])
|
err := cmd.Flag.Parse(args[1:])
|
||||||
} else {
|
if err != nil {
|
||||||
module = "false"
|
beeLogger.Log.Fatal("Parse args err " + err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var appPath string
|
var appPath string
|
||||||
var packPath string
|
var packPath string
|
||||||
var err error
|
var err error
|
||||||
if module != `true` {
|
if gopath == `true` {
|
||||||
beeLogger.Log.Info("generate api project support GOPATH")
|
beeLogger.Log.Info("generate api project support GOPATH")
|
||||||
version.ShowShortVersionBanner()
|
version.ShowShortVersionBanner()
|
||||||
appPath, packPath, err = utils.CheckEnv(args[0])
|
appPath, packPath, err = utils.CheckEnv(args[0])
|
||||||
@ -605,7 +607,7 @@ func createAPI(cmd *commands.Command, args []string) int {
|
|||||||
beeLogger.Log.Info("Creating API...")
|
beeLogger.Log.Info("Creating API...")
|
||||||
|
|
||||||
os.MkdirAll(appPath, 0755)
|
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")
|
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()))
|
utils.WriteToFile(path.Join(appPath, "go.mod"), fmt.Sprintf(goMod, packPath, utils.GetGoVersionSkipMinor(), beegoVersion.String()))
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ var CmdHproseapp = &commands.Command{
|
|||||||
|
|
||||||
{{"To scaffold out your application, use:"|bold}}
|
{{"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
|
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.
|
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
|
require github.com/smartystreets/goconvey v1.6.4
|
||||||
`
|
`
|
||||||
|
|
||||||
var module utils.DocValue
|
var gopath utils.DocValue
|
||||||
var beegoVersion utils.DocValue
|
var beegoVersion utils.DocValue
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
CmdHproseapp.Flag.Var(&generate.Tables, "tables", "List of table names separated by a comma.")
|
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.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(&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(&gopath, "gopath", "Support go path,default false")
|
||||||
CmdHproseapp.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by -module=true")
|
CmdHproseapp.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by go mod")
|
||||||
commands.AvailableCommands = append(commands.AvailableCommands, CmdHproseapp)
|
commands.AvailableCommands = append(commands.AvailableCommands, CmdHproseapp)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,15 +71,16 @@ func createhprose(cmd *commands.Command, args []string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
curpath, _ := os.Getwd()
|
curpath, _ := os.Getwd()
|
||||||
if len(args) > 1 {
|
if len(args) >= 2 {
|
||||||
cmd.Flag.Parse(args[1:])
|
err := cmd.Flag.Parse(args[1:])
|
||||||
} else {
|
if err != nil {
|
||||||
module = "false"
|
beeLogger.Log.Fatal("Parse args err " + err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var apppath string
|
var apppath string
|
||||||
var packpath string
|
var packpath string
|
||||||
var err error
|
var err error
|
||||||
if module != `true` {
|
if gopath == `true` {
|
||||||
beeLogger.Log.Info("generate api project support GOPATH")
|
beeLogger.Log.Info("generate api project support GOPATH")
|
||||||
version.ShowShortVersionBanner()
|
version.ShowShortVersionBanner()
|
||||||
apppath, packpath, err = utils.CheckEnv(args[0])
|
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...")
|
beeLogger.Log.Info("Creating Hprose application...")
|
||||||
|
|
||||||
os.MkdirAll(apppath, 0755)
|
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")
|
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()))
|
utils.WriteToFile(path.Join(apppath, "go.mod"), fmt.Sprintf(goMod, packpath, utils.GetGoVersionSkipMinor(), beegoVersion.String()))
|
||||||
}
|
}
|
||||||
|
@ -31,12 +31,12 @@ var gopath utils.DocValue
|
|||||||
var beegoVersion utils.DocValue
|
var beegoVersion utils.DocValue
|
||||||
|
|
||||||
var CmdNew = &commands.Command{
|
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",
|
Short: "Creates a Beego application",
|
||||||
Long: `
|
Long: `
|
||||||
Creates a Beego application for the given app name in the current directory.
|
Creates a Beego application for the given app name in the current directory.
|
||||||
now supoort generate a go modules project
|
now default 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:
|
The command 'new' creates a folder named [appname] [-gopath=false] [-beego=v1.12.1] and generates the following structure:
|
||||||
|
|
||||||
├── main.go
|
├── main.go
|
||||||
├── go.mod
|
├── go.mod
|
||||||
@ -255,8 +255,8 @@ var reloadJsClient = `function b(a){var c=new WebSocket(a);c.onclose=function(){
|
|||||||
`
|
`
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
CmdNew.Flag.Var(&gopath, "gopath", "Support go path")
|
CmdNew.Flag.Var(&gopath, "gopath", "Support go path,default false")
|
||||||
CmdNew.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by module mod")
|
CmdNew.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by go mod")
|
||||||
commands.AvailableCommands = append(commands.AvailableCommands, CmdNew)
|
commands.AvailableCommands = append(commands.AvailableCommands, CmdNew)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,11 +34,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func GetBeeWorkPath() string {
|
func GetBeeWorkPath() string {
|
||||||
beePath, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
curpath, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return beePath
|
return curpath
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go is a basic promise implementation: it wraps calls a function in a goroutine
|
// 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) {
|
func CheckEnv(appname string) (apppath, packpath string, err error) {
|
||||||
gps := GetGOPATHs()
|
gps := GetGOPATHs()
|
||||||
if len(gps) == 0 {
|
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")
|
beeLogger.Log.Fatal("GOPATH environment variable is not set or empty")
|
||||||
}
|
}
|
||||||
currpath, _ := os.Getwd()
|
currpath, _ := os.Getwd()
|
||||||
|
Loading…
Reference in New Issue
Block a user