1
0
mirror of https://github.com/beego/bee.git synced 2024-11-21 23:50:54 +00:00
bee/g.go
2014-06-19 21:09:17 +08:00

60 lines
1.6 KiB
Go

// Copyright 2013 bee authors
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package main
import "os"
var cmdGenerate = &Command{
UsageLine: "generate [Command]",
Short: "generate code based on application",
Long: `
bee g model [modelfile] [dbconfig]
generate model base on struct
bee g controller [modelfile]
generate RESTFul controllers based on modelfile
bee g router [controllerfile]
generate router based on controllerfile
bee g docs
generate swagger doc file
bee g test [routerfile]
generate testcase
`,
}
func generateCode(cmd *Command, args []string) {
curpath, _ := os.Getwd()
if len(args) < 1 {
ColorLog("[ERRO] command is missing\n")
os.Exit(2)
}
gopath := os.Getenv("GOPATH")
Debugf("gopath:%s", gopath)
if gopath == "" {
ColorLog("[ERRO] $GOPATH not found\n")
ColorLog("[HINT] Set $GOPATH in your environment vairables\n")
os.Exit(2)
}
gcmd := args[0]
switch gcmd {
case "docs":
generateDocs(curpath)
default:
ColorLog("[ERRO] command is missing\n")
}
ColorLog("[SUCC] generate successfully created!\n")
}