Skip to content

Commit

Permalink
Merge pull request #735 from flycash/v1.12.3
Browse files Browse the repository at this point in the history
V1.12.3
  • Loading branch information
flycash authored Nov 8, 2020
2 parents 5005bd4 + 57309c3 commit d459bbf
Show file tree
Hide file tree
Showing 22 changed files with 324 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
go:
- 1.12.17
- 1.14.11
install:
- export PATH=$PATH:$HOME/gopath/bin
- go get -u github.com/opennota/check/cmd/structcheck
Expand Down
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Bee is a command-line tool facilitating development of Beego-based application.
To install `bee` use the `go get` command:

```bash
go get github.com/beego/bee
go get github.com/beego/bee@v1.12.3
```

Then you can add `bee` binary to PATH environment variable in your `~/.bashrc` or `~/.bash_profile` file:
Expand All @@ -25,12 +25,6 @@ Then you can add `bee` binary to PATH environment variable in your `~/.bashrc` o
export PATH=$PATH:<your_main_gopath>/bin
```

> If you already have `bee` installed, updating `bee` is simple:
```bash
go get -u github.com/beego/bee
```

## Basic commands

Bee provides a variety of commands which can be helpful at various stages of development. The top level commands include:
Expand Down
1 change: 1 addition & 0 deletions cmd/bee.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
_ "github.com/beego/bee/cmd/commands/rs"
_ "github.com/beego/bee/cmd/commands/run"
_ "github.com/beego/bee/cmd/commands/server"
_ "github.com/beego/bee/cmd/commands/update"
_ "github.com/beego/bee/cmd/commands/version"
"github.com/beego/bee/utils"
)
Expand Down
22 changes: 12 additions & 10 deletions cmd/commands/api/apiapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ var CmdApiapp = &commands.Command{
Short: "Creates a Beego API application",
Long: `
The command 'api' creates a Beego API application.
now default supoort generate a go modules project.
{{"Example:"|bold}}
$ bee api [appname] [-tables=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"] [-module=true] [-beego=v1.12.1]
$ bee api [appname] [-tables=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"] [-gopath=false] [-beego=v1.12.1]
If 'conn' argument is empty, the command will generate an example API application. Otherwise the command
will connect to your database and generate models based on the existing tables.
The command 'api' creates a folder named [appname] with the following structure:
├── main.go
├── go.mod
├── go.mod
├── {{"conf"|foldername}}
│ └── app.conf
├── {{"controllers"|foldername}}
Expand Down Expand Up @@ -543,15 +544,15 @@ func TestGet(t *testing.T) {
}
`
var module utils.DocValue
var gopath utils.DocValue
var beegoVersion utils.DocValue

func init() {
CmdApiapp.Flag.Var(&generate.Tables, "tables", "List of table names separated by a comma.")
CmdApiapp.Flag.Var(&generate.SQLDriver, "driver", "Database driver. Either mysql, postgres or sqlite.")
CmdApiapp.Flag.Var(&generate.SQLConn, "conn", "Connection string used by the driver to connect to a database instance.")
CmdApiapp.Flag.Var(&module, "module", "Support go modules")
CmdApiapp.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by -module=true")
CmdApiapp.Flag.Var(&gopath, "gopath", "Support go path,default false")
CmdApiapp.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by go mod")
commands.AvailableCommands = append(commands.AvailableCommands, CmdApiapp)
}

Expand All @@ -563,14 +564,15 @@ func createAPI(cmd *commands.Command, args []string) int {
}

if len(args) >= 2 {
cmd.Flag.Parse(args[1:])
} else {
module = "false"
err := cmd.Flag.Parse(args[1:])
if err != nil {
beeLogger.Log.Fatal("Parse args err " + err.Error())
}
}
var appPath string
var packPath string
var err error
if module != `true` {
if gopath == `true` {
beeLogger.Log.Info("generate api project support GOPATH")
version.ShowShortVersionBanner()
appPath, packPath, err = utils.CheckEnv(args[0])
Expand Down Expand Up @@ -605,7 +607,7 @@ func createAPI(cmd *commands.Command, args []string) int {
beeLogger.Log.Info("Creating API...")

os.MkdirAll(appPath, 0755)
if module == `true` { //generate first for calc model name
if gopath != `true` { //generate first for calc model name
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "go.mod"), "\x1b[0m")
utils.WriteToFile(path.Join(appPath, "go.mod"), fmt.Sprintf(goMod, packPath, utils.GetGoVersionSkipMinor(), beegoVersion.String()))
}
Expand Down
1 change: 1 addition & 0 deletions cmd/commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (c *Command) Out() io.Writer {
if c.output != nil {
return *c.output
}

return colors.NewColorWriter(os.Stderr)
}

Expand Down
21 changes: 11 additions & 10 deletions cmd/commands/hprose/hprose.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var CmdHproseapp = &commands.Command{
{{"To scaffold out your application, use:"|bold}}
$ bee hprose [appname] [-tables=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"] [-module=true] [-beego=v1.12.1]
$ bee hprose [appname] [-tables=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"] [-gopath=false] [-beego=v1.12.1]
If 'conn' is empty, the command will generate a sample application. Otherwise the command
will connect to your database and generate models based on the existing tables.
Expand Down Expand Up @@ -52,15 +52,15 @@ require github.com/astaxie/beego %s
require github.com/smartystreets/goconvey v1.6.4
`

var module utils.DocValue
var gopath utils.DocValue
var beegoVersion utils.DocValue

func init() {
CmdHproseapp.Flag.Var(&generate.Tables, "tables", "List of table names separated by a comma.")
CmdHproseapp.Flag.Var(&generate.SQLDriver, "driver", "Database driver. Either mysql, postgres or sqlite.")
CmdHproseapp.Flag.Var(&generate.SQLConn, "conn", "Connection string used by the driver to connect to a database instance.")
CmdHproseapp.Flag.Var(&module, "module", "Support go modules")
CmdHproseapp.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by -module=true")
CmdHproseapp.Flag.Var(&gopath, "gopath", "Support go path,default false")
CmdHproseapp.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by go mod")
commands.AvailableCommands = append(commands.AvailableCommands, CmdHproseapp)
}

Expand All @@ -71,15 +71,16 @@ func createhprose(cmd *commands.Command, args []string) int {
}

curpath, _ := os.Getwd()
if len(args) > 1 {
cmd.Flag.Parse(args[1:])
} else {
module = "false"
if len(args) >= 2 {
err := cmd.Flag.Parse(args[1:])
if err != nil {
beeLogger.Log.Fatal("Parse args err " + err.Error())
}
}
var apppath string
var packpath string
var err error
if module != `true` {
if gopath == `true` {
beeLogger.Log.Info("generate api project support GOPATH")
version.ShowShortVersionBanner()
apppath, packpath, err = utils.CheckEnv(args[0])
Expand Down Expand Up @@ -109,7 +110,7 @@ func createhprose(cmd *commands.Command, args []string) int {
beeLogger.Log.Info("Creating Hprose application...")

os.MkdirAll(apppath, 0755)
if module == `true` { //generate first for calc model name
if gopath != `true` { //generate first for calc model name
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "go.mod"), "\x1b[0m")
utils.WriteToFile(path.Join(apppath, "go.mod"), fmt.Sprintf(goMod, packpath, utils.GetGoVersionSkipMinor(), beegoVersion.String()))
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/commands/new/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ var gopath utils.DocValue
var beegoVersion utils.DocValue

var CmdNew = &commands.Command{
UsageLine: "new [appname] [-module=true] [-beego=v1.12.1]",
UsageLine: "new [appname] [-gopath=false] [-beego=v1.12.1]",
Short: "Creates a Beego application",
Long: `
Creates a Beego application for the given app name in the current directory.
now supoort generate a go modules project
The command 'new' creates a folder named [appname] [-module=true] [-beego=v1.12.1] and generates the following structure:
now default supoort generate a go modules project
The command 'new' creates a folder named [appname] [-gopath=false] [-beego=v1.12.1] and generates the following structure:
├── main.go
├── go.mod
Expand Down Expand Up @@ -255,8 +255,8 @@ var reloadJsClient = `function b(a){var c=new WebSocket(a);c.onclose=function(){
`

func init() {
CmdNew.Flag.Var(&gopath, "gopath", "Support go path")
CmdNew.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by module mod")
CmdNew.Flag.Var(&gopath, "gopath", "Support go path,default false")
CmdNew.Flag.Var(&beegoVersion, "beego", "set beego version,only take effect by go mod")
commands.AvailableCommands = append(commands.AvailableCommands, CmdNew)
}

Expand Down
38 changes: 38 additions & 0 deletions cmd/commands/update/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package update

import (
"flag"
"os"
"os/exec"

"github.com/beego/bee/cmd/commands"
"github.com/beego/bee/config"
beeLogger "github.com/beego/bee/logger"
)

var CmdUpdate = &commands.Command{
UsageLine: "update",
Short: "Update Bee",
Long: `
Automatic run command "go get -u github.com/beego/bee" for selfupdate
`,
Run: updateBee,
}

func init() {
fs := flag.NewFlagSet("update", flag.ContinueOnError)
CmdUpdate.Flag = *fs
commands.AvailableCommands = append(commands.AvailableCommands, CmdUpdate)
}

func updateBee(cmd *commands.Command, args []string) int {
beeLogger.Log.Info("Updating")
beePath := config.GitRemotePath
cmdUp := exec.Command("go", "get", "-u", beePath)
cmdUp.Stdout = os.Stdout
cmdUp.Stderr = os.Stderr
if err := cmdUp.Run(); err != nil {
beeLogger.Log.Warnf("Run cmd err:%s",err)
}
return 0
}
6 changes: 4 additions & 2 deletions cmd/commands/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import (
"runtime"
"strings"

"gopkg.in/yaml.v2"

"github.com/beego/bee/cmd/commands"
"github.com/beego/bee/config"
beeLogger "github.com/beego/bee/logger"
"github.com/beego/bee/logger/colors"
"github.com/beego/bee/utils"
"gopkg.in/yaml.v2"
)

const verboseVersionBanner string = `%s%s______
Expand Down Expand Up @@ -57,7 +59,7 @@ Prints the current Bee, Beego and Go version alongside the platform information.
}
var outputFormat string

const version = "1.11.0"
const version = config.Version

func init() {
fs := flag.NewFlagSet("version", flag.ContinueOnError)
Expand Down
9 changes: 8 additions & 1 deletion config/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ import (
"os"
"path/filepath"

beeLogger "github.com/beego/bee/logger"
"gopkg.in/yaml.v2"

beeLogger "github.com/beego/bee/logger"
)

const confVer = 0

const (
Version = "1.12.0"
GitRemotePath = "github.com/beego/bee"
)


var Conf = struct {
Version int
WatchExts []string `json:"watch_ext" yaml:"watch_ext"`
Expand Down
46 changes: 17 additions & 29 deletions generate/swaggergen/g_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"errors"
"fmt"
"go/ast"
"go/build"
"go/parser"
"go/token"
"os"
Expand All @@ -37,7 +38,6 @@ import (
"github.com/astaxie/beego/swagger"
"github.com/astaxie/beego/utils"
beeLogger "github.com/beego/bee/logger"
bu "github.com/beego/bee/utils"
)

const (
Expand Down Expand Up @@ -102,8 +102,8 @@ func init() {
astPkgs = make([]*ast.Package, 0)
}

// ParsePackagesFromDir parses packages from a given directory
func ParsePackagesFromDir(dirpath string) {
// parsePackagesFromDir parses packages from a given directory
func parsePackagesFromDir(dirpath string) {
c := make(chan error)

go func() {
Expand Down Expand Up @@ -157,8 +157,14 @@ func parsePackageFromDir(path string) error {

// GenerateDocs generates documentations for a given path.
func GenerateDocs(curpath string) {
fset := token.NewFileSet()
pkgspath := curpath
workspace := os.Getenv("BeeWorkspace")
if workspace != "" {
pkgspath = workspace
}
parsePackagesFromDir(pkgspath)

fset := token.NewFileSet()
f, err := parser.ParseFile(fset, filepath.Join(curpath, "routers", "router.go"), nil, parser.ParseComments)
if err != nil {
beeLogger.Log.Fatalf("Error while parsing router.go: %s", err)
Expand Down Expand Up @@ -263,7 +269,7 @@ func GenerateDocs(curpath string) {
if im.Name != nil {
localName = im.Name.Name
}
analyseControllerPkg(path.Join(curpath, "vendor"), localName, im.Path.Value)
analyseControllerPkg(localName, im.Path.Value)
}
for _, d := range f.Decls {
switch specDecl := d.(type) {
Expand Down Expand Up @@ -418,7 +424,7 @@ func analyseNSInclude(baseurl string, ce *ast.CallExpr) string {
return cname
}

func analyseControllerPkg(vendorPath, localName, pkgpath string) {
func analyseControllerPkg(localName, pkgpath string) {
pkgpath = strings.Trim(pkgpath, "\"")
if isSystemPackage(pkgpath) {
return
Expand All @@ -433,36 +439,18 @@ func analyseControllerPkg(vendorPath, localName, pkgpath string) {
importlist[pps[len(pps)-1]] = pkgpath
}

pkgRealpath := ""

if bu.IsGOMODULE() {
pkgRealpath = filepath.Join(bu.GetBeeWorkPath(), "..", pkgpath)
} else {
gopaths := bu.GetGOPATHs()
if len(gopaths) == 0 {
beeLogger.Log.Fatal("GOPATH environment variable is not set or empty")
}
wg, _ := filepath.EvalSymlinks(filepath.Join(vendorPath, pkgpath))
if utils.FileExists(wg) {
pkgRealpath = wg
} else {
wgopath := gopaths
for _, wg := range wgopath {
wg, _ = filepath.EvalSymlinks(filepath.Join(wg, "src", pkgpath))
if utils.FileExists(wg) {
pkgRealpath = wg
break
}
}
}
pkg, err := build.Default.Import(pkgpath, ".", build.FindOnly)
if err != nil {
beeLogger.Log.Fatalf("Package %s cannot be imported: %v", pkgpath, err)
}
pkgRealpath := pkg.Dir
if pkgRealpath != "" {
if _, ok := pkgCache[pkgpath]; ok {
return
}
pkgCache[pkgpath] = struct{}{}
} else {
beeLogger.Log.Fatalf("Package '%s' does not exist in the GOPATH or vendor path", pkgpath)
beeLogger.Log.Fatalf("Package '%s' does not have source directory", pkgpath)
}

fileSet := token.NewFileSet()
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module github.com/beego/bee

go 1.13
go 1.14

require (
github.com/BurntSushi/toml v0.3.1
github.com/astaxie/beego v1.12.1
github.com/davecgh/go-spew v1.1.1
github.com/flosch/pongo2 v0.0.0-20200529170236-5abacdfa4915
Expand Down
Loading

0 comments on commit d459bbf

Please sign in to comment.