Skip to content

Commit

Permalink
Merge pull request #752 from beego/develop
Browse files Browse the repository at this point in the history
Develop to master
  • Loading branch information
flycash authored Dec 16, 2020
2 parents 5005bd4 + 3b2304a commit 4eb58f5
Show file tree
Hide file tree
Showing 64 changed files with 989 additions and 957 deletions.
2 changes: 1 addition & 1 deletion .goxc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
}
},
"ConfigVersion": "0.9"
}
}
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.6
install:
- export PATH=$PATH:$HOME/gopath/bin
- go get -u github.com/opennota/check/cmd/structcheck
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,4 @@ third-party archives.
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.
limitations under the License.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ clean:
publish:
mkdir -p bin/$(VERSION)
cd bin/$(VERSION)
xgo -v -x --targets="windows/*,darwin/*,linux/386,linux/amd64,linux/arm-5,linux/arm64" -out bee_$(VERSION) github.com/beego/bee
xgo -v -x --targets="windows/*,darwin/*,linux/386,linux/amd64,linux/arm-5,linux/arm64" -out bee_$(VERSION) github.com/beego/bee/v2
cd ..
ghr -u beego -r bee $(VERSION) $(VERSION)
ghr -u beego -r bee $(VERSION) $(VERSION)
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Bee is a command-line tool facilitating development of Beego-based application.

## Requirements

- Go version >= 1.12.
- Go version >= 1.12

## Installation

To install `bee` use the `go get` command:

```bash
go get github.com/beego/bee
go get github.com/beego/bee/v2
```

Then you can add `bee` binary to PATH environment variable in your `~/.bashrc` or `~/.bash_profile` file:
Expand All @@ -28,7 +28,7 @@ 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
go get -u github.com/beego/bee/v2
```

## Basic commands
Expand Down Expand Up @@ -355,7 +355,7 @@ Breakpoint 1 set at 0x40100f for main.main() ./main.go:8
> main.main() ./main.go:8 (hits goroutine(1):1 total:1) (PC: 0x40100f)
3: import (
4: _ "github.com/user/myapp/routers"
5: "github.com/astaxie/beego"
5: beego "github.com/beego/beego/v2/server/web"
6: )
7:
=> 8: func main() {
Expand Down
2 changes: 1 addition & 1 deletion bee.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
"driver": "mysql"
},
"enable_reload": false
}
}
38 changes: 21 additions & 17 deletions cmd/bee.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,25 @@
package cmd

import (
"github.com/beego/bee/cmd/commands"
_ "github.com/beego/bee/cmd/commands/api"
_ "github.com/beego/bee/cmd/commands/bale"
_ "github.com/beego/bee/cmd/commands/beefix"
_ "github.com/beego/bee/cmd/commands/beegopro"
_ "github.com/beego/bee/cmd/commands/dlv"
_ "github.com/beego/bee/cmd/commands/dockerize"
_ "github.com/beego/bee/cmd/commands/generate"
_ "github.com/beego/bee/cmd/commands/hprose"
_ "github.com/beego/bee/cmd/commands/migrate"
_ "github.com/beego/bee/cmd/commands/new"
_ "github.com/beego/bee/cmd/commands/pack"
_ "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/version"
"github.com/beego/bee/utils"
"github.com/beego/bee/v2/cmd/commands"
_ "github.com/beego/bee/v2/cmd/commands/api"
_ "github.com/beego/bee/v2/cmd/commands/bale"
_ "github.com/beego/bee/v2/cmd/commands/beefix"
_ "github.com/beego/bee/v2/cmd/commands/beegopro"
_ "github.com/beego/bee/v2/cmd/commands/dev"
_ "github.com/beego/bee/v2/cmd/commands/dlv"
_ "github.com/beego/bee/v2/cmd/commands/dockerize"
_ "github.com/beego/bee/v2/cmd/commands/generate"
_ "github.com/beego/bee/v2/cmd/commands/hprose"
_ "github.com/beego/bee/v2/cmd/commands/migrate"
_ "github.com/beego/bee/v2/cmd/commands/new"
_ "github.com/beego/bee/v2/cmd/commands/pack"
_ "github.com/beego/bee/v2/cmd/commands/rs"
_ "github.com/beego/bee/v2/cmd/commands/run"
_ "github.com/beego/bee/v2/cmd/commands/server"
_ "github.com/beego/bee/v2/cmd/commands/update"
_ "github.com/beego/bee/v2/cmd/commands/version"
"github.com/beego/bee/v2/utils"
)

func IfGenerateDocs(name string, args []string) bool {
Expand All @@ -49,6 +51,8 @@ func IfGenerateDocs(name string, args []string) bool {

var usageTemplate = `Bee is a Fast and Flexible tool for managing your Beego Web Application.
You are using bee for beego v2.x. If you are working on beego v1.x, please downgrade version to bee v1.12.0
{{"USAGE" | headline}}
{{"bee command [arguments]" | bold}}
Expand Down
56 changes: 30 additions & 26 deletions cmd/commands/api/apiapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ package apiapp

import (
"fmt"
"github.com/beego/bee/logger/colors"
"os"
path "path/filepath"
"strings"

"github.com/beego/bee/cmd/commands"
"github.com/beego/bee/cmd/commands/version"
"github.com/beego/bee/generate"
beeLogger "github.com/beego/bee/logger"
"github.com/beego/bee/utils"
"github.com/beego/bee/v2/logger/colors"

"github.com/beego/bee/v2/cmd/commands"
"github.com/beego/bee/v2/cmd/commands/version"
"github.com/beego/bee/v2/generate"
beeLogger "github.com/beego/bee/v2/logger"
"github.com/beego/bee/v2/utils"
)

var CmdApiapp = &commands.Command{
Expand All @@ -34,17 +35,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.3]
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 @@ -74,7 +76,7 @@ var apiMaingo = `package main
import (
_ "{{.Appname}}/routers"
"github.com/astaxie/beego"
beego "github.com/beego/beego/v2/server/web"
)
func main() {
Expand All @@ -91,8 +93,8 @@ var apiMainconngo = `package main
import (
_ "{{.Appname}}/routers"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
beego "github.com/beego/beego/v2/server/web"
"github.com/beego/beego/v2/client/orm"
{{.DriverPkg}}
)
Expand All @@ -111,7 +113,7 @@ module %s
go %s
require github.com/astaxie/beego %s
require github.com/beego/beego/v2 %s
require github.com/smartystreets/goconvey v1.6.4
`

Expand All @@ -127,7 +129,7 @@ package routers
import (
"{{.Appname}}/controllers"
"github.com/astaxie/beego"
beego "github.com/beego/beego/v2/server/web"
)
func init() {
Expand Down Expand Up @@ -296,7 +298,7 @@ import (
"{{.Appname}}/models"
"encoding/json"
"github.com/astaxie/beego"
beego "github.com/beego/beego/v2/server/web"
)
// Operations about object
Expand Down Expand Up @@ -389,7 +391,7 @@ import (
"{{.Appname}}/models"
"encoding/json"
"github.com/astaxie/beego"
beego "github.com/beego/beego/v2/server/web"
)
// Operations about Users
Expand Down Expand Up @@ -514,7 +516,8 @@ import (
"path/filepath"
_ "{{.Appname}}/routers"
"github.com/astaxie/beego"
beego "github.com/beego/beego/v2/server/web"
"github.com/beego/beego/v2/core/logs"
. "github.com/smartystreets/goconvey/convey"
)
Expand All @@ -530,7 +533,7 @@ func TestGet(t *testing.T) {
w := httptest.NewRecorder()
beego.BeeApp.Handlers.ServeHTTP(w, r)
beego.Trace("testing", "TestGet", "Code[%d]\n%s", w.Code, w.Body.String())
logs.Info("testing", "TestGet", "Code[%d]\n%s", w.Code, w.Body.String())
Convey("Subject: Test Station Endpoint\n", t, func() {
Convey("Status Code Should Be 200", func() {
Expand All @@ -543,15 +546,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 +566,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 All @@ -582,7 +586,7 @@ func createAPI(cmd *commands.Command, args []string) int {
appPath = path.Join(utils.GetBeeWorkPath(), args[0])
packPath = args[0]
if beegoVersion.String() == `` {
beegoVersion.Set(`v1.12.1`)
beegoVersion.Set(utils.BEEGO_VERSION)
}
}

Expand All @@ -605,7 +609,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
10 changes: 5 additions & 5 deletions cmd/commands/bale/bale.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"runtime"
"strings"

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

var CmdBale = &commands.Command{
Expand Down
Loading

0 comments on commit 4eb58f5

Please sign in to comment.