diff --git a/apiapp.go b/apiapp.go index ca0a7dc..fcdb9cf 100644 --- a/apiapp.go +++ b/apiapp.go @@ -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 } diff --git a/fix.go b/fix.go index 5e7487e..4e408f0 100644 --- a/fix.go +++ b/fix.go @@ -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{ diff --git a/g.go b/g.go index 04fca0d..60f5c1b 100644 --- a/g.go +++ b/g.go @@ -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) } diff --git a/g_appcode.go b/g_appcode.go index ac0efaf..b01c4ae 100644 --- a/g_appcode.go +++ b/g_appcode.go @@ -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) } diff --git a/g_controller.go b/g_controller.go index 90daea2..c5a9995 100644 --- a/g_controller.go +++ b/g_controller.go @@ -15,10 +15,10 @@ package main import ( + "fmt" "os" "path" "strings" - "fmt" ) // article diff --git a/g_docs.go b/g_docs.go index 229540a..f265436 100644 --- a/g_docs.go +++ b/g_docs.go @@ -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) diff --git a/g_model.go b/g_model.go index 4ebfb02..8d8fdf4 100644 --- a/g_model.go +++ b/g_model.go @@ -1,10 +1,10 @@ package main import ( + "fmt" "os" "path" "strings" - "fmt" ) func generateModel(mname, fields, crupath string) { @@ -30,7 +30,7 @@ func generateModel(mname, fields, crupath string) { defer f.Close() var content string if fields != "" { - generateStructure(modelName,fields,crupath) + generateStructure(modelName, fields, crupath) content = strings.Replace(CRUD_MODEL_TPL, "{{packageName}}", packageName, -1) pkgPath := getPackagePath(crupath) content = strings.Replace(content, "{{pkgPath}}", pkgPath, -1) diff --git a/g_views.go b/g_views.go index 47c252c..c278a03 100644 --- a/g_views.go +++ b/g_views.go @@ -1,9 +1,9 @@ package main import ( + "fmt" "os" "path" - "fmt" ) // recipe diff --git a/migrate.go b/migrate.go index 7bb27f7..b4e4ac3 100644 --- a/migrate.go +++ b/migrate.go @@ -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 { diff --git a/new.go b/new.go index efc9571..0668a64 100644 --- a/new.go +++ b/new.go @@ -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) @@ -87,42 +94,42 @@ func createApp(cmd *Command, args []string) int { ColorLog("[INFO] Creating application...\n") os.MkdirAll(apppath, 0755) - fmt.Println("\tcreate\t", apppath + string(path.Separator)) + fmt.Println("\tcreate\t", apppath+string(path.Separator)) os.Mkdir(path.Join(apppath, "conf"), 0755) - fmt.Println("\tcreate\t", path.Join(apppath, "conf") + string(path.Separator)) + fmt.Println("\tcreate\t", path.Join(apppath, "conf")+string(path.Separator)) os.Mkdir(path.Join(apppath, "controllers"), 0755) - fmt.Println("\tcreate\t", path.Join(apppath, "controllers") + string(path.Separator)) + fmt.Println("\tcreate\t", path.Join(apppath, "controllers")+string(path.Separator)) os.Mkdir(path.Join(apppath, "helpers"), 0755) - fmt.Println("\tcreate\t", path.Join(apppath, "helpers") + string(path.Separator)) + fmt.Println("\tcreate\t", path.Join(apppath, "helpers")+string(path.Separator)) os.Mkdir(path.Join(apppath, "models"), 0755) - fmt.Println("\tcreate\t", path.Join(apppath, "models") + string(path.Separator)) + fmt.Println("\tcreate\t", path.Join(apppath, "models")+string(path.Separator)) os.Mkdir(path.Join(apppath, "routers"), 0755) - fmt.Println("\tcreate\t", path.Join(apppath, "routers") + string(path.Separator)) + fmt.Println("\tcreate\t", path.Join(apppath, "routers")+string(path.Separator)) os.Mkdir(path.Join(apppath, "tests"), 0755) - fmt.Println("\tcreate\t", path.Join(apppath, "tests") + string(path.Separator)) + fmt.Println("\tcreate\t", path.Join(apppath, "tests")+string(path.Separator)) os.Mkdir(path.Join(apppath, "structures"), 0755) - fmt.Println("\tcreate\t", path.Join(apppath, "structures") + string(path.Separator)) + fmt.Println("\tcreate\t", path.Join(apppath, "structures")+string(path.Separator)) os.Mkdir(path.Join(apppath, "static"), 0755) - fmt.Println("\tcreate\t", path.Join(apppath, "static") + string(path.Separator)) + fmt.Println("\tcreate\t", path.Join(apppath, "static")+string(path.Separator)) os.Mkdir(path.Join(apppath, "static", "js"), 0755) - fmt.Println("\tcreate\t", path.Join(apppath, "static", "js") + string(path.Separator)) + fmt.Println("\tcreate\t", path.Join(apppath, "static", "js")+string(path.Separator)) os.Mkdir(path.Join(apppath, "static", "css"), 0755) - fmt.Println("\tcreate\t", path.Join(apppath, "static", "css") + string(path.Separator)) + fmt.Println("\tcreate\t", path.Join(apppath, "static", "css")+string(path.Separator)) os.Mkdir(path.Join(apppath, "static", "img"), 0755) - fmt.Println("\tcreate\t", path.Join(apppath, "static", "img") + string(path.Separator)) + fmt.Println("\tcreate\t", path.Join(apppath, "static", "img")+string(path.Separator)) - fmt.Println("\tcreate\t", path.Join(apppath, "views") + string(path.Separator)) + fmt.Println("\tcreate\t", path.Join(apppath, "views")+string(path.Separator)) os.Mkdir(path.Join(apppath, "views"), 0755) fmt.Println("\tcreate\t", path.Join(apppath, "conf", "app.conf")) diff --git a/version.go b/version.go index 43931e1..25f303e 100644 --- a/version.go +++ b/version.go @@ -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 = `______ | ___ \ | |_/ / ___ ___ | ___ \ / _ \ / _ \