Skip to content

Commit d459bbf

Browse files
authored
Merge pull request #735 from flycash/v1.12.3
V1.12.3
2 parents 5005bd4 + 57309c3 commit d459bbf

File tree

22 files changed

+324
-167
lines changed

22 files changed

+324
-167
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: go
22
go:
3-
- 1.12.17
3+
- 1.14.11
44
install:
55
- export PATH=$PATH:$HOME/gopath/bin
66
- go get -u github.com/opennota/check/cmd/structcheck

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Bee is a command-line tool facilitating development of Beego-based application.
1616
To install `bee` use the `go get` command:
1717

1818
```bash
19-
go get github.com/beego/bee
19+
go get github.com/beego/bee@v1.12.3
2020
```
2121

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

28-
> If you already have `bee` installed, updating `bee` is simple:
29-
30-
```bash
31-
go get -u github.com/beego/bee
32-
```
33-
3428
## Basic commands
3529

3630
Bee provides a variety of commands which can be helpful at various stages of development. The top level commands include:

cmd/bee.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
_ "github.com/beego/bee/cmd/commands/rs"
3232
_ "github.com/beego/bee/cmd/commands/run"
3333
_ "github.com/beego/bee/cmd/commands/server"
34+
_ "github.com/beego/bee/cmd/commands/update"
3435
_ "github.com/beego/bee/cmd/commands/version"
3536
"github.com/beego/bee/utils"
3637
)

cmd/commands/api/apiapp.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,18 @@ var CmdApiapp = &commands.Command{
3434
Short: "Creates a Beego API application",
3535
Long: `
3636
The command 'api' creates a Beego API application.
37+
now default supoort generate a go modules project.
3738
3839
{{"Example:"|bold}}
39-
$ bee api [appname] [-tables=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"] [-module=true] [-beego=v1.12.1]
40+
$ bee api [appname] [-tables=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"] [-gopath=false] [-beego=v1.12.1]
4041
4142
If 'conn' argument is empty, the command will generate an example API application. Otherwise the command
4243
will connect to your database and generate models based on the existing tables.
4344
4445
The command 'api' creates a folder named [appname] with the following structure:
4546
4647
├── main.go
47-
├── go.mod
48+
├── go.mod
4849
├── {{"conf"|foldername}}
4950
│ └── app.conf
5051
├── {{"controllers"|foldername}}
@@ -543,15 +544,15 @@ func TestGet(t *testing.T) {
543544
}
544545
545546
`
546-
var module utils.DocValue
547+
var gopath utils.DocValue
547548
var beegoVersion utils.DocValue
548549

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

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

565566
if len(args) >= 2 {
566-
cmd.Flag.Parse(args[1:])
567-
} else {
568-
module = "false"
567+
err := cmd.Flag.Parse(args[1:])
568+
if err != nil {
569+
beeLogger.Log.Fatal("Parse args err " + err.Error())
570+
}
569571
}
570572
var appPath string
571573
var packPath string
572574
var err error
573-
if module != `true` {
575+
if gopath == `true` {
574576
beeLogger.Log.Info("generate api project support GOPATH")
575577
version.ShowShortVersionBanner()
576578
appPath, packPath, err = utils.CheckEnv(args[0])
@@ -605,7 +607,7 @@ func createAPI(cmd *commands.Command, args []string) int {
605607
beeLogger.Log.Info("Creating API...")
606608

607609
os.MkdirAll(appPath, 0755)
608-
if module == `true` { //generate first for calc model name
610+
if gopath != `true` { //generate first for calc model name
609611
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "go.mod"), "\x1b[0m")
610612
utils.WriteToFile(path.Join(appPath, "go.mod"), fmt.Sprintf(goMod, packPath, utils.GetGoVersionSkipMinor(), beegoVersion.String()))
611613
}

cmd/commands/command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func (c *Command) Out() io.Writer {
6565
if c.output != nil {
6666
return *c.output
6767
}
68+
6869
return colors.NewColorWriter(os.Stderr)
6970
}
7071

cmd/commands/hprose/hprose.go

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

55-
var module utils.DocValue
55+
var gopath utils.DocValue
5656
var beegoVersion utils.DocValue
5757

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

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

7373
curpath, _ := os.Getwd()
74-
if len(args) > 1 {
75-
cmd.Flag.Parse(args[1:])
76-
} else {
77-
module = "false"
74+
if len(args) >= 2 {
75+
err := cmd.Flag.Parse(args[1:])
76+
if err != nil {
77+
beeLogger.Log.Fatal("Parse args err " + err.Error())
78+
}
7879
}
7980
var apppath string
8081
var packpath string
8182
var err error
82-
if module != `true` {
83+
if gopath == `true` {
8384
beeLogger.Log.Info("generate api project support GOPATH")
8485
version.ShowShortVersionBanner()
8586
apppath, packpath, err = utils.CheckEnv(args[0])
@@ -109,7 +110,7 @@ func createhprose(cmd *commands.Command, args []string) int {
109110
beeLogger.Log.Info("Creating Hprose application...")
110111

111112
os.MkdirAll(apppath, 0755)
112-
if module == `true` { //generate first for calc model name
113+
if gopath != `true` { //generate first for calc model name
113114
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "go.mod"), "\x1b[0m")
114115
utils.WriteToFile(path.Join(apppath, "go.mod"), fmt.Sprintf(goMod, packpath, utils.GetGoVersionSkipMinor(), beegoVersion.String()))
115116
}

cmd/commands/new/new.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ var gopath utils.DocValue
3131
var beegoVersion utils.DocValue
3232

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

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

cmd/commands/update/update.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package update
2+
3+
import (
4+
"flag"
5+
"os"
6+
"os/exec"
7+
8+
"github.com/beego/bee/cmd/commands"
9+
"github.com/beego/bee/config"
10+
beeLogger "github.com/beego/bee/logger"
11+
)
12+
13+
var CmdUpdate = &commands.Command{
14+
UsageLine: "update",
15+
Short: "Update Bee",
16+
Long: `
17+
Automatic run command "go get -u github.com/beego/bee" for selfupdate
18+
`,
19+
Run: updateBee,
20+
}
21+
22+
func init() {
23+
fs := flag.NewFlagSet("update", flag.ContinueOnError)
24+
CmdUpdate.Flag = *fs
25+
commands.AvailableCommands = append(commands.AvailableCommands, CmdUpdate)
26+
}
27+
28+
func updateBee(cmd *commands.Command, args []string) int {
29+
beeLogger.Log.Info("Updating")
30+
beePath := config.GitRemotePath
31+
cmdUp := exec.Command("go", "get", "-u", beePath)
32+
cmdUp.Stdout = os.Stdout
33+
cmdUp.Stderr = os.Stderr
34+
if err := cmdUp.Run(); err != nil {
35+
beeLogger.Log.Warnf("Run cmd err:%s",err)
36+
}
37+
return 0
38+
}

cmd/commands/version/version.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ import (
1414
"runtime"
1515
"strings"
1616

17+
"gopkg.in/yaml.v2"
18+
1719
"github.com/beego/bee/cmd/commands"
20+
"github.com/beego/bee/config"
1821
beeLogger "github.com/beego/bee/logger"
1922
"github.com/beego/bee/logger/colors"
2023
"github.com/beego/bee/utils"
21-
"gopkg.in/yaml.v2"
2224
)
2325

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

60-
const version = "1.11.0"
62+
const version = config.Version
6163

6264
func init() {
6365
fs := flag.NewFlagSet("version", flag.ContinueOnError)

config/conf.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@ import (
1919
"os"
2020
"path/filepath"
2121

22-
beeLogger "github.com/beego/bee/logger"
2322
"gopkg.in/yaml.v2"
23+
24+
beeLogger "github.com/beego/bee/logger"
2425
)
2526

2627
const confVer = 0
2728

29+
const (
30+
Version = "1.12.0"
31+
GitRemotePath = "github.com/beego/bee"
32+
)
33+
34+
2835
var Conf = struct {
2936
Version int
3037
WatchExts []string `json:"watch_ext" yaml:"watch_ext"`

0 commit comments

Comments
 (0)