mirror of
https://github.com/beego/bee.git
synced 2025-04-01 14:55:58 +00:00
Merge branch 'develop' into fix-load-config
This commit is contained in:
commit
609ed8fcd5
@ -27,6 +27,7 @@ import (
|
|||||||
_ "github.com/beego/bee/cmd/commands/new"
|
_ "github.com/beego/bee/cmd/commands/new"
|
||||||
_ "github.com/beego/bee/cmd/commands/pack"
|
_ "github.com/beego/bee/cmd/commands/pack"
|
||||||
_ "github.com/beego/bee/cmd/commands/run"
|
_ "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/cmd/commands/version"
|
||||||
"github.com/beego/bee/utils"
|
"github.com/beego/bee/utils"
|
||||||
)
|
)
|
||||||
|
44
cmd/commands/scripts/scripts.go
Normal file
44
cmd/commands/scripts/scripts.go
Normal 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
|
||||||
|
}
|
@ -35,8 +35,9 @@ var Conf = struct {
|
|||||||
Envs []string
|
Envs []string
|
||||||
Bale bale
|
Bale bale
|
||||||
Database database
|
Database database
|
||||||
EnableReload bool `json:"enable_reload" yaml:"enable_reload"`
|
EnableReload bool `json:"enable_reload" yaml:"enable_reload"`
|
||||||
EnableNotification bool `json:"enable_notification" yaml:"enable_notification"`
|
EnableNotification bool `json:"enable_notification" yaml:"enable_notification"`
|
||||||
|
Scripts map[string]string `json:"scripts" yaml:"scripts"`
|
||||||
}{
|
}{
|
||||||
GoInstall: true,
|
GoInstall: true,
|
||||||
DirStruct: dirStruct{
|
DirStruct: dirStruct{
|
||||||
@ -52,6 +53,7 @@ var Conf = struct {
|
|||||||
Driver: "mysql",
|
Driver: "mysql",
|
||||||
},
|
},
|
||||||
EnableNotification: true,
|
EnableNotification: true,
|
||||||
|
Scripts: map[string]string{},
|
||||||
}
|
}
|
||||||
|
|
||||||
// gopm support
|
// gopm support
|
||||||
|
@ -1,3 +1,16 @@
|
|||||||
|
// Copyright 2017 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 utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -21,9 +34,9 @@ func Notify(text, title string) {
|
|||||||
case "darwin":
|
case "darwin":
|
||||||
osxNotify(text, title)
|
osxNotify(text, title)
|
||||||
case "linux":
|
case "linux":
|
||||||
windowsNotify(text, title)
|
|
||||||
case "windows":
|
|
||||||
linuxNotify(text, title)
|
linuxNotify(text, title)
|
||||||
|
case "windows":
|
||||||
|
windowsNotify(text, title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +58,7 @@ func windowsNotify(text, title string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func linuxNotify(text, title string) {
|
func linuxNotify(text, title string) {
|
||||||
exec.Command("notify-send", "-i", "", title, text)
|
exec.Command("notify-send", "-i", "", title, text).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func existTerminalNotifier() bool {
|
func existTerminalNotifier() bool {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user