Skip to content

Commit

Permalink
Merge pull request #690 from beego/feature/beegopro
Browse files Browse the repository at this point in the history
Feature/beegopro
  • Loading branch information
askuy authored Jul 19, 2020
2 parents c37857e + cc2b2d1 commit b90f934
Show file tree
Hide file tree
Showing 26 changed files with 2,031 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Bee is a command-line tool facilitating development of Beego-based application.

## Requirements

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

## Installation

Expand Down
1 change: 1 addition & 0 deletions cmd/bee.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
_ "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"
Expand Down
59 changes: 59 additions & 0 deletions cmd/commands/beegopro/beegopro.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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 beegopro

import (
"github.com/beego/bee/cmd/commands"
"github.com/beego/bee/internal/app/module/beegopro"
"github.com/beego/bee/logger"
"strings"
)

var CmdBeegoPro = &commands.Command{
UsageLine: "pro [command]",
Short: "Source code generator",
Long: ``,
Run: BeegoPro,
}

func init() {
CmdBeegoPro.Flag.Var(&beegopro.SQL, "sql", "sql file path")
CmdBeegoPro.Flag.Var(&beegopro.SQLMode, "sqlmode", "sql mode")
CmdBeegoPro.Flag.Var(&beegopro.SQLModePath, "sqlpath", "sql mode path")
commands.AvailableCommands = append(commands.AvailableCommands, CmdBeegoPro)
}

func BeegoPro(cmd *commands.Command, args []string) int {
if len(args) < 1 {
beeLogger.Log.Fatal("Command is missing")
}

if len(args) >= 2 {
cmd.Flag.Parse(args[1:])
}

gcmd := args[0]
switch gcmd {
case "gen":
beegopro.DefaultBeegoPro.Run()
case "config":
beegopro.DefaultBeegoPro.GenConfig()
case "migration":
beegopro.DefaultBeegoPro.Migration(args)
default:
beeLogger.Log.Fatal("Command is missing")
}
beeLogger.Log.Successf("%s successfully generated!", strings.Title(gcmd))
return 0
}
25 changes: 15 additions & 10 deletions cmd/commands/new/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/beego/bee/utils"
)

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

var CmdNew = &commands.Command{
Expand Down Expand Up @@ -89,8 +89,7 @@ func init() {
beego.Router("/", &controllers.MainController{})
}
`
var goMod = `
module %s
var goMod = `module %s
go %s
Expand Down Expand Up @@ -256,8 +255,8 @@ var reloadJsClient = `function b(a){var c=new WebSocket(a);c.onclose=function(){
`

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

Expand All @@ -268,14 +267,15 @@ func CreateApp(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 new project support GOPATH")
version.ShowShortVersionBanner()
appPath, packPath, err = utils.CheckEnv(args[0])
Expand All @@ -301,8 +301,13 @@ func CreateApp(cmd *commands.Command, args []string) int {

beeLogger.Log.Info("Creating application...")

// If it is the current directory, select the current folder name to package path
if packPath == "." {
packPath = path.Base(appPath)
}

os.MkdirAll(appPath, 0755)
if module == `true` {
if gopath != `true` {
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
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ module github.com/beego/bee
go 1.13

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
github.com/fsnotify/fsnotify v1.4.9
github.com/gadelkareem/delve v1.4.2-0.20200619175259-dcd01330766f
github.com/go-sql-driver/mysql v1.5.0
github.com/gorilla/websocket v1.4.2
github.com/lib/pq v1.7.0
github.com/pelletier/go-toml v1.2.0
github.com/smartwalle/pongo2render v1.0.1
github.com/spf13/viper v1.7.0
gopkg.in/yaml.v2 v2.3.0
)
Loading

0 comments on commit b90f934

Please sign in to comment.