1
0
mirror of https://github.com/beego/bee.git synced 2024-12-18 08:30:50 +00:00

Merge pull request #373 from sergeylanzman/add-scripts-options

add scripts option(custom commands)
This commit is contained in:
astaxie 2017-03-16 23:27:10 +08:00 committed by GitHub
commit fd4772fe82
3 changed files with 48 additions and 2 deletions

View File

@ -27,6 +27,7 @@ import (
_ "github.com/beego/bee/cmd/commands/new"
_ "github.com/beego/bee/cmd/commands/pack"
_ "github.com/beego/bee/cmd/commands/run"
_ "github.com/beego/bee/cmd/commands/scripts"
_ "github.com/beego/bee/cmd/commands/version"
"github.com/beego/bee/utils"
)

View File

@ -0,0 +1,44 @@
package scripts
import (
"os/exec"
"os"
"runtime"
"strings"
"github.com/beego/bee/cmd/commands"
"github.com/beego/bee/cmd/commands/version"
"github.com/beego/bee/config"
"github.com/beego/bee/logger"
)
func init() {
for commandName, command := range config.Conf.Scripts {
CmdNew := &commands.Command{
UsageLine: commandName,
Short: command,
PreRun: func(cmd *commands.Command, args []string) { version.ShowShortVersionBanner() },
Run: RunScript,
}
commands.AvailableCommands = append(commands.AvailableCommands, CmdNew)
}
}
func RunScript(cmd *commands.Command, args []string) int {
var c *exec.Cmd
switch runtime.GOOS {
case "darwin", "linux":
c = exec.Command("sh", "-c", cmd.Short+" "+strings.Join(args, " "))
case "windows": //TODO
}
c.Stdout = os.Stdout
c.Stderr = os.Stderr
err := c.Run()
if err != nil {
beeLogger.Log.Error(err.Error())
}
return 0
}

View File

@ -78,8 +78,9 @@ var Conf struct {
Driver string
Conn string
}
EnableReload bool `json:"enable_reload" yaml:"enable_reload"`
EnableNotification bool `json:"enable_notification" yaml:"enable_notification"`
EnableReload bool `json:"enable_reload" yaml:"enable_reload"`
EnableNotification bool `json:"enable_notification" yaml:"enable_notification"`
Scripts map[string]string `json:"scripts" yaml:"scripts"`
}
func init() {