1
0
mirror of https://github.com/beego/bee.git synced 2024-12-22 20:20:49 +00:00
This commit is contained in:
astaxie 2014-08-18 11:52:06 +08:00
commit f97e13c5aa
12 changed files with 24 additions and 14 deletions

View File

@ -542,7 +542,7 @@ func init() {
cmdApiapp.Flag.Var(&conn, "conn", "connection string used by the driver to connect to a database instance")
}
func createapi(cmd *Command, args []string) {
func createapi(cmd *Command, args []string) int {
curpath, _ := os.Getwd()
if len(args) > 1 {
cmd.Flag.Parse(args[1:])
@ -621,6 +621,7 @@ func createapi(cmd *Command, args []string) {
writetofile(path.Join(apppath, "main.go"),
strings.Replace(apiMaingo, "{{.Appname}}", packpath, -1))
}
return 0
}
func checkEnv(appname string) (apppath, packpath string, err error) {

View File

@ -44,8 +44,9 @@ func init() {
cmdRouter.Run = autoRouter
}
func autoRouter(cmd *Command, args []string) {
func autoRouter(cmd *Command, args []string) int {
fmt.Println("[INFO] Starting auto-generating routers...")
return 0
}
// getControllerInfo returns controllers that embeded "beego.controller"

View File

@ -43,7 +43,7 @@ func init() {
cmdBale.Run = runBale
}
func runBale(cmd *Command, args []string) {
func runBale(cmd *Command, args []string) int {
err := loadConfig()
if err != nil {
ColorLog("[ERRO] Fail to parse bee.json[ %s ]\n", err)
@ -82,6 +82,7 @@ func runBale(cmd *Command, args []string) {
}
ColorLog("[SUCC] Baled resources successfully!\n")
return 0
}
const (

5
bee.go
View File

@ -30,7 +30,7 @@ const version = "1.2.1"
type Command struct {
// Run runs the command.
// The args are the arguments after the command name.
Run func(cmd *Command, args []string)
Run func(cmd *Command, args []string) int
// UsageLine is the one-line usage message.
// The first word in the line is taken to be the command name.
@ -110,8 +110,7 @@ func main() {
cmd.Flag.Parse(args[1:])
args = cmd.Flag.Args()
}
cmd.Run(cmd, args)
os.Exit(2)
os.Exit(cmd.Run(cmd, args))
return
}
}

3
g.go
View File

@ -71,7 +71,7 @@ func init() {
cmdGenerate.Flag.Var(&fields, "fields", "specify the fields want to generate.")
}
func generateCode(cmd *Command, args []string) {
func generateCode(cmd *Command, args []string) int {
curpath, _ := os.Getwd()
if len(args) < 1 {
ColorLog("[ERRO] command is missing\n")
@ -199,4 +199,5 @@ func generateCode(cmd *Command, args []string) {
ColorLog("[ERRO] command is missing\n")
}
ColorLog("[SUCC] generate successfully created!\n")
return 0
}

View File

@ -61,7 +61,7 @@ func init() {
}
// runMigration is the entry point for starting a migration
func runMigration(cmd *Command, args []string) {
func runMigration(cmd *Command, args []string) int {
crupath, _ := os.Getwd()
gopath := os.Getenv("GOPATH")
@ -117,6 +117,7 @@ func runMigration(cmd *Command, args []string) {
}
}
ColorLog("[SUCC] Migration successful!\n")
return 0
}
// migrateUpdate does the schema update

3
new.go
View File

@ -55,7 +55,7 @@ func init() {
cmdNew.Run = createApp
}
func createApp(cmd *Command, args []string) {
func createApp(cmd *Command, args []string) int {
curpath, _ := os.Getwd()
if len(args) != 1 {
ColorLog("[ERRO] Argument [appname] is missing\n")
@ -139,6 +139,7 @@ func createApp(cmd *Command, args []string) {
writetofile(path.Join(apppath, "main.go"), strings.Replace(maingo, "{{.Appname}}", strings.Join(strings.Split(apppath[len(appsrcpath)+1:], string(path.Separator)), "/"), -1))
ColorLog("[SUCC] New application successfully created!\n")
return 0
}
var appconf = `appname = {{.Appname}}

View File

@ -469,7 +469,7 @@ func isBeegoProject(thePath string) bool {
return false
}
func packApp(cmd *Command, args []string) {
func packApp(cmd *Command, args []string) int {
curPath, _ := os.Getwd()
thePath := ""
@ -624,4 +624,5 @@ func packApp(cmd *Command, args []string) {
}
fmt.Printf("file write to `%s`\n", outputP)
return 0
}

3
run.go
View File

@ -58,7 +58,7 @@ func init() {
var appname string
func runApp(cmd *Command, args []string) {
func runApp(cmd *Command, args []string) int {
exit := make(chan bool)
crupath, _ := os.Getwd()
@ -119,6 +119,7 @@ func runApp(cmd *Command, args []string) {
runtime.Goexit()
}
}
return 0
}
func readAppDirectories(directory string, paths *[]string) {

View File

@ -57,7 +57,7 @@ func init() {
cmdRundocs.Flag.Var(&docport, "docport", "doc server port")
}
func runDocs(cmd *Command, args []string) {
func runDocs(cmd *Command, args []string) int {
if isDownload == "true" {
downloadFromUrl(swaggerlink, "swagger.zip")
err := unzipAndDelete("swagger.zip", "swagger")
@ -74,6 +74,7 @@ func runDocs(cmd *Command, args []string) {
}
fmt.Println("start the docs server on: http://127.0.0.1:" + docport)
log.Fatal(http.ListenAndServe(":"+string(docport), http.FileServer(http.Dir("swagger"))))
return 0
}
func downloadFromUrl(url, fileName string) {

View File

@ -49,7 +49,7 @@ func pathExists(path string) bool {
var started = make(chan bool)
func testApp(cmd *Command, args []string) {
func testApp(cmd *Command, args []string) int {
if len(args) != 1 {
ColorLog("[ERRO] Cannot start running[ %s ]\n",
"argument 'appname' is missing")
@ -73,6 +73,7 @@ func testApp(cmd *Command, args []string) {
runTest()
}
}
return 0
}
func runTest() {

View File

@ -27,7 +27,7 @@ func init() {
cmdVersion.Run = versionCmd
}
func versionCmd(cmd *Command, args []string) {
func versionCmd(cmd *Command, args []string) int {
fmt.Println("bee :" + version)
fmt.Println("beego :" + getbeegoVersion())
//fmt.Println("Go :" + runtime.Version())
@ -36,6 +36,7 @@ func versionCmd(cmd *Command, args []string) {
log.Fatal(err)
}
fmt.Println("Go :" + string(goversion))
return 0
}
func getbeegoVersion() string {