From 55741df579ef39e431a6f0e6d468658f6d3b72af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=9B=E7=90=A6?= Date: Fri, 15 Aug 2014 17:38:51 +0800 Subject: [PATCH] return actual value from subcommand --- apiapp.go | 3 ++- autorouter.go | 3 ++- bale.go | 3 ++- bee.go | 5 ++--- g.go | 3 ++- migrate.go | 3 ++- new.go | 3 ++- pack.go | 3 ++- run.go | 3 ++- rundocs.go | 3 ++- test.go | 3 ++- version.go | 3 ++- 12 files changed, 24 insertions(+), 14 deletions(-) diff --git a/apiapp.go b/apiapp.go index 65bb906..8ee8c85 100644 --- a/apiapp.go +++ b/apiapp.go @@ -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) { diff --git a/autorouter.go b/autorouter.go index 99dee37..1273551 100644 --- a/autorouter.go +++ b/autorouter.go @@ -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" diff --git a/bale.go b/bale.go index 64c275d..27ee6d1 100644 --- a/bale.go +++ b/bale.go @@ -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 ( diff --git a/bee.go b/bee.go index 3118ac3..30905cd 100644 --- a/bee.go +++ b/bee.go @@ -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 } } diff --git a/g.go b/g.go index 2523e08..1f08fd0 100644 --- a/g.go +++ b/g.go @@ -69,7 +69,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") @@ -193,4 +193,5 @@ func generateCode(cmd *Command, args []string) { ColorLog("[ERRO] command is missing\n") } ColorLog("[SUCC] generate successfully created!\n") + return 0 } diff --git a/migrate.go b/migrate.go index ebc04fa..9db0ce3 100644 --- a/migrate.go +++ b/migrate.go @@ -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 diff --git a/new.go b/new.go index 8d87b71..50c8f1d 100644 --- a/new.go +++ b/new.go @@ -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}} diff --git a/pack.go b/pack.go index 9f1d041..6a605d2 100644 --- a/pack.go +++ b/pack.go @@ -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 } diff --git a/run.go b/run.go index 9976fe9..2d74f87 100644 --- a/run.go +++ b/run.go @@ -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) { diff --git a/rundocs.go b/rundocs.go index ae1442d..13b0a9a 100644 --- a/rundocs.go +++ b/rundocs.go @@ -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) { diff --git a/test.go b/test.go index 0cef690..6790c42 100644 --- a/test.go +++ b/test.go @@ -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() { diff --git a/version.go b/version.go index e3d917c..15da074 100644 --- a/version.go +++ b/version.go @@ -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 {