mirror of
https://github.com/beego/bee.git
synced 2024-11-21 23:50:54 +00:00
fix use path/filepath intead path
This commit is contained in:
parent
354ef35f16
commit
a73c185d16
83
createapp.go
83
createapp.go
@ -3,7 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
path "path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -17,18 +17,18 @@ In the current path, will create a folder named [appname]
|
|||||||
|
|
||||||
In the appname folder has the follow struct:
|
In the appname folder has the follow struct:
|
||||||
|
|
||||||
|- main.go
|
|- main.go
|
||||||
|- conf
|
|- conf
|
||||||
|- app.conf
|
|- app.conf
|
||||||
|- controllers
|
|- controllers
|
||||||
|- default.go
|
|- default.go
|
||||||
|- models
|
|- models
|
||||||
|- static
|
|- static
|
||||||
|- js
|
|- js
|
||||||
|- css
|
|- css
|
||||||
|- img
|
|- img
|
||||||
|- views
|
|- views
|
||||||
index.tpl
|
index.tpl
|
||||||
|
|
||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
@ -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, ";")
|
|
||||||
if len(wgopath) >= 1 {
|
|
||||||
for _, wg := range wgopath {
|
|
||||||
wg = wg + `\src`
|
|
||||||
if strings.HasPrefix(crupath, wg) {
|
|
||||||
haspath = true
|
|
||||||
appsrcpath = path.Join(strings.TrimPrefix(crupath, wg), args[0])
|
|
||||||
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 {
|
wgopath := path.SplitList(gopath)
|
||||||
haspath = true
|
for _, wg := range wgopath {
|
||||||
appsrcpath = args[0]
|
wg = path.Join(wg, "src")
|
||||||
|
|
||||||
|
if path.HasPrefix(strings.ToLower(curpath), strings.ToLower(wg)) {
|
||||||
|
haspath = true
|
||||||
|
appsrcpath = wg
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = `
|
||||||
|
Loading…
Reference in New Issue
Block a user