1
0
mirror of https://github.com/beego/bee.git synced 2024-11-21 23:50:54 +00:00

Merge pull request #9 from slene/master

use path/filepath intead path
This commit is contained in:
astaxie 2013-06-26 06:16:21 -07:00
commit fc59287801
2 changed files with 38 additions and 47 deletions

View File

@ -3,7 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"path" path "path/filepath"
"strings" "strings"
) )
@ -38,11 +38,12 @@ func init() {
} }
func createapp(cmd *Command, args []string) { func createapp(cmd *Command, args []string) {
crupath, _ := os.Getwd() curpath, _ := os.Getwd()
if len(args) != 1 { if len(args) != 1 {
fmt.Println("error args") fmt.Println("error args")
os.Exit(2) os.Exit(2)
} }
gopath := os.Getenv("GOPATH") gopath := os.Getenv("GOPATH")
if gopath == "" { if gopath == "" {
fmt.Println("you should set GOPATH in the env") fmt.Println("you should set GOPATH in the env")
@ -50,42 +51,32 @@ func createapp(cmd *Command, args []string) {
} }
haspath := false haspath := false
appsrcpath := "" appsrcpath := ""
if crupath != path.Join(gopath, "src") {
wgopath := strings.Split(gopath, ";") wgopath := path.SplitList(gopath)
if len(wgopath) >= 1 {
for _, wg := range wgopath { for _, wg := range wgopath {
wg = wg + `\src` wg = path.Join(wg, "src")
if strings.HasPrefix(crupath, wg) {
if path.HasPrefix(strings.ToLower(curpath), strings.ToLower(wg)) {
haspath = true haspath = true
appsrcpath = path.Join(strings.TrimPrefix(crupath, wg), args[0]) appsrcpath = wg
break break
} }
} }
}
if !haspath {
lgopath := strings.Split(gopath, ":")
if len(lgopath) >= 1 {
for _, wg := range lgopath {
if strings.HasPrefix(crupath, path.Join(wg, "src")) {
haspath = true
appsrcpath = path.Join(strings.TrimPrefix(crupath, path.Join(wg, "src")), args[0])
break
}
}
}
}
} else {
haspath = true
appsrcpath = args[0]
}
if !haspath { if !haspath {
fmt.Println("can't create application outside of GOPATH") fmt.Printf("can't create application outside of GOPATH `%s`\n", gopath)
fmt.Println("you first should `cd $GOPATH/src` then use create") fmt.Printf("you first should `cd $GOPATH%ssrc` then use create\n", string(path.Separator))
os.Exit(2) os.Exit(2)
} }
apppath := path.Join(crupath, args[0])
os.Mkdir(apppath, 0755) apppath := path.Join(curpath, args[0])
if _, err := os.Stat(apppath); os.IsNotExist(err) == false {
fmt.Printf("path `%s` exists, can not create app without remove it\n", apppath)
os.Exit(2)
}
os.MkdirAll(apppath, 0755)
fmt.Println("create app folder:", apppath) fmt.Println("create app folder:", apppath)
os.Mkdir(path.Join(apppath, "conf"), 0755) os.Mkdir(path.Join(apppath, "conf"), 0755)
fmt.Println("create conf:", path.Join(apppath, "conf")) fmt.Println("create conf:", path.Join(apppath, "conf"))
@ -113,7 +104,7 @@ func createapp(cmd *Command, args []string) {
writetofile(path.Join(apppath, "views", "index.tpl"), indextpl) writetofile(path.Join(apppath, "views", "index.tpl"), indextpl)
fmt.Println("create main.go:", path.Join(apppath, "main.go")) fmt.Println("create main.go:", path.Join(apppath, "main.go"))
writetofile(path.Join(apppath, "main.go"), strings.Replace(maingo, "{{.Appname}}", strings.TrimPrefix(strings.Replace(appsrcpath, "\\", "/", -1), "/"), -1)) writetofile(path.Join(apppath, "main.go"), strings.Replace(maingo, "{{.Appname}}", strings.Join(strings.Split(apppath[len(appsrcpath)+1:], string(path.Separator)), "/"), -1))
} }
var appconf = ` var appconf = `

View File

@ -3,7 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"path" path "path/filepath"
) )
var cmdStart = &Command{ var cmdStart = &Command{