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

Fixed double GOPATH issue

Default Crawl GOPATH full path
So we will achieve complete double GOPATH
Ex: / XXX: / CCCC
But just need to pick up: / CCCC
This commit is contained in:
Dylan 2016-07-11 18:35:35 +08:00
parent 9069078ac0
commit 304e6cc0a4
11 changed files with 92 additions and 56 deletions

View File

@ -632,16 +632,18 @@ func createapi(cmd *Command, args []string) int {
} else {
os.Mkdir(path.Join(apppath, "models"), 0755)
fmt.Println("\tcreate\t", path.Join(apppath, "models"))
os.Mkdir(path.Join(apppath, "routers"), 0755)
fmt.Println("create routers:", path.Join(apppath, "routers"))
os.Mkdir(path.Join(apppath, "structures"), 0755)
fmt.Println("create structures:", path.Join(apppath, "structures"))
fmt.Println("create controllers object_controller.go:", path.Join(apppath, "controllers", "object_controller.go"))
os.Mkdir(path.Join(apppath, "routers"), 0755)
fmt.Println("\tcreate\t", path.Join(apppath, "routers"))
os.Mkdir(path.Join(apppath, "structures"), 0755)
fmt.Println("\tcreate\t", path.Join(apppath, "structures"))
fmt.Println("\tcreate\t", path.Join(apppath, "controllers", "object_controller.go"))
WriteToFile(path.Join(apppath, "controllers", "object_controller.go"),
strings.Replace(apiControllers, "{{.Appname}}", packpath, -1))
fmt.Println("create controllers user_controller.go:", path.Join(apppath, "controllers", "user_controller.go"))
fmt.Println("\tcreate\t", path.Join(apppath, "controllers", "user_controller.go"))
WriteToFile(path.Join(apppath, "controllers", "user_controller.go"),
strings.Replace(apiControllers2, "{{.Appname}}", packpath, -1))
@ -653,24 +655,24 @@ func createapi(cmd *Command, args []string) int {
WriteToFile(path.Join(apppath, "routers", "router.go"),
strings.Replace(apirouter, "{{.Appname}}", packpath, -1))
fmt.Println("create models object.go:", path.Join(apppath, "models", "object.go"))
fmt.Println("\tcreate\t", path.Join(apppath, "models", "object.go"))
WriteToFile(path.Join(apppath, "models", "object.go"),
strings.Replace(apiModels, "{{.Appname}}", packpath, -1))
fmt.Println("create models user.go:", path.Join(apppath, "models", "user.go"))
fmt.Println("\tcreate\t", path.Join(apppath, "models", "user.go"))
WriteToFile(path.Join(apppath, "models", "user.go"),
strings.Replace(apiModels2, "{{.Appname}}", packpath, -1))
fmt.Println("create structures user_structure.go:", path.Join(apppath, "structures", "user_structure.go"))
fmt.Println("\tcreate\t", path.Join(apppath, "structures", "user_structure.go"))
WriteToFile(path.Join(apppath, "structures", "user_structure.go"), apistructures)
fmt.Println("create structures object_structure.go:", path.Join(apppath, "structures", "object_structure.go"))
fmt.Println("\tcreate\t", path.Join(apppath, "structures", "object_structure.go"))
WriteToFile(path.Join(apppath, "structures", "object_structure.go"), apistructures2)
fmt.Println("create helpers user_helper.go:", path.Join(apppath, "helpers", "user_helper.go"))
fmt.Println("\tcreate\t", path.Join(apppath, "helpers", "user_helper.go"))
WriteToFile(path.Join(apppath, "helpers", "user_helper.go"), "package helpers")
fmt.Println("create helpers object_helper.go:", path.Join(apppath, "helpers", "object_helper.go"))
fmt.Println("\tcreate\t", path.Join(apppath, "helpers", "object_helper.go"))
WriteToFile(path.Join(apppath, "helpers", "object_helper.go"), "package helpers")
fmt.Println("\tcreate\t", path.Join(apppath, "docs", "doc.go"))
@ -685,9 +687,16 @@ func createapi(cmd *Command, args []string) int {
}
func checkEnv(appname string) (apppath, packpath string, err error) {
gopath := os.Getenv("GOPATH")
Debugf("gopath:%s", gopath)
if gopath == "" {
gopaths := GetGOPATHs()
Debugf("gopath:%s", gopaths)
gopath := ""
switch len(gopaths) {
case 1:
gopath = gopaths[0]
case 2:
gopath = gopaths[1]
default:
err = fmt.Errorf("you should set GOPATH in the env")
return
}

2
fix.go
View File

@ -1,6 +1,7 @@
package main
import (
"fmt"
"go/parser"
"go/token"
"io/ioutil"
@ -8,7 +9,6 @@ import (
"path/filepath"
"regexp"
"strings"
"fmt"
)
var cmdFix = &Command{

8
g.go
View File

@ -94,11 +94,11 @@ func generateCode(cmd *Command, args []string) int {
os.Exit(2)
}
gopath := os.Getenv("GOPATH")
Debugf("gopath:%s", gopath)
if gopath == "" {
gopaths := GetGOPATHs()
Debugf("gopath:%s", gopaths)
if len(gopaths) == 0 {
ColorLog("[ERRO] $GOPATH not found\n")
ColorLog("[HINT] Set $GOPATH in your environment vairables\n")
ColorLog("[HINT] Set $GOPATH in your environment variables\n")
os.Exit(2)
}

View File

@ -1030,10 +1030,18 @@ func getFileName(tbName string) (filename string) {
}
func getPackagePath(curpath string) (packpath string) {
gopath := os.Getenv("GOPATH")
Debugf("gopath:%s", gopath)
if gopath == "" {
ColorLog("[ERRO] you should set GOPATH in the env")
gopaths := GetGOPATHs()
Debugf("gopath:%s", gopaths)
gopath := ""
switch len(gopaths) {
case 1:
gopath = gopaths[0]
case 2:
gopath = gopaths[1]
default:
ColorLog("[ERRO] $GOPATH not found\n")
ColorLog("[HINT] Set $GOPATH in your environment variables\n")
os.Exit(2)
}

View File

@ -15,10 +15,10 @@
package main
import (
"fmt"
"os"
"path"
"strings"
"fmt"
)
// article

View File

@ -276,10 +276,22 @@ func analisyscontrollerPkg(localName, pkgpath string) {
if pkgpath == "github.com/astaxie/beego" {
return
}
gopath := os.Getenv("GOPATH")
if gopath == "" {
panic("please set gopath")
gopaths := GetGOPATHs()
Debugf("gopath:%s", gopaths)
gopath := ""
switch len(gopaths) {
case 1:
gopath = gopaths[0]
case 2:
gopath = gopaths[1]
default:
ColorLog("[ERRO] $GOPATH not found\n")
ColorLog("[HINT] Set $GOPATH in your environment variables\n")
os.Exit(2)
}
pkgRealpath := ""
wgopath := filepath.SplitList(gopath)

View File

@ -1,10 +1,10 @@
package main
import (
"fmt"
"os"
"path"
"strings"
"fmt"
)
func generateModel(mname, fields, crupath string) {

View File

@ -1,9 +1,9 @@
package main
import (
"fmt"
"os"
"path"
"fmt"
)
// recipe

View File

@ -66,13 +66,15 @@ func runMigration(cmd *Command, args []string) int {
crupath, _ := os.Getwd()
gopath := os.Getenv("GOPATH")
Debugf("gopath:%s", gopath)
if gopath == "" {
gopaths := GetGOPATHs()
Debugf("gopath:%s", gopaths)
if len(gopaths) == 0 {
ColorLog("[ERRO] $GOPATH not found\n")
ColorLog("[HINT] Set $GOPATH in your environment vairables\n")
ColorLog("[HINT] Set $GOPATH in your environment variables\n")
os.Exit(2)
}
// load config
err := loadConfig()
if err != nil {

13
new.go
View File

@ -65,9 +65,16 @@ func createApp(cmd *Command, args []string) int {
os.Exit(2)
}
gopath := os.Getenv("GOPATH")
Debugf("gopath:%s", gopath)
if gopath == "" {
gopaths := GetGOPATHs()
Debugf("gopath:%s", gopaths)
gopath := ""
switch len(gopaths) {
case 1:
gopath = gopaths[0]
case 2:
gopath = gopaths[1]
default:
ColorLog("[ERRO] $GOPATH not found\n")
ColorLog("[HINT] Set $GOPATH in your environment variables\n")
os.Exit(2)

View File

@ -2,12 +2,12 @@ package main
import (
"bufio"
"bytes"
"fmt"
"io"
"os"
path "path/filepath"
"regexp"
"bytes"
)
var cmdVersion = &Command{
@ -24,8 +24,7 @@ bee version
`,
}
const verboseVersionBanner =
`______
const verboseVersionBanner = `______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
@ -43,8 +42,7 @@ Compiler : {{ .Compiler }}
Date : {{ Now "Monday, 2 Jan 2006" }}
`
const shortVersionBanner =
`______
const shortVersionBanner = `______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \