1
0
mirror of https://github.com/beego/bee.git synced 2024-11-22 20:20:55 +00:00

Merge pull request #51 from DigGe/master

return actual value from subcommand
This commit is contained in:
astaxie 2014-08-18 11:51:12 +08:00
commit a08b881651
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") 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() curpath, _ := os.Getwd()
if len(args) > 1 { if len(args) > 1 {
cmd.Flag.Parse(args[1:]) cmd.Flag.Parse(args[1:])
@ -621,6 +621,7 @@ func createapi(cmd *Command, args []string) {
writetofile(path.Join(apppath, "main.go"), writetofile(path.Join(apppath, "main.go"),
strings.Replace(apiMaingo, "{{.Appname}}", packpath, -1)) strings.Replace(apiMaingo, "{{.Appname}}", packpath, -1))
} }
return 0
} }
func checkEnv(appname string) (apppath, packpath string, err error) { func checkEnv(appname string) (apppath, packpath string, err error) {

View File

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

View File

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

5
bee.go
View File

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

3
g.go
View File

@ -69,7 +69,7 @@ func init() {
cmdGenerate.Flag.Var(&fields, "fields", "specify the fields want to generate.") 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() curpath, _ := os.Getwd()
if len(args) < 1 { if len(args) < 1 {
ColorLog("[ERRO] command is missing\n") ColorLog("[ERRO] command is missing\n")
@ -193,4 +193,5 @@ func generateCode(cmd *Command, args []string) {
ColorLog("[ERRO] command is missing\n") ColorLog("[ERRO] command is missing\n")
} }
ColorLog("[SUCC] generate successfully created!\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 // 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() crupath, _ := os.Getwd()
gopath := os.Getenv("GOPATH") gopath := os.Getenv("GOPATH")
@ -117,6 +117,7 @@ func runMigration(cmd *Command, args []string) {
} }
} }
ColorLog("[SUCC] Migration successful!\n") ColorLog("[SUCC] Migration successful!\n")
return 0
} }
// migrateUpdate does the schema update // migrateUpdate does the schema update

3
new.go
View File

@ -55,7 +55,7 @@ func init() {
cmdNew.Run = createApp cmdNew.Run = createApp
} }
func createApp(cmd *Command, args []string) { func createApp(cmd *Command, args []string) int {
curpath, _ := os.Getwd() curpath, _ := os.Getwd()
if len(args) != 1 { if len(args) != 1 {
ColorLog("[ERRO] Argument [appname] is missing\n") 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)) 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") ColorLog("[SUCC] New application successfully created!\n")
return 0
} }
var appconf = `appname = {{.Appname}} var appconf = `appname = {{.Appname}}

View File

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

3
run.go
View File

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

View File

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

View File

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

View File

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