From d1330dfc0bb2052ad3f700d3a7b06209ed5b594a Mon Sep 17 00:00:00 2001 From: Sergey Lanzman Date: Sat, 11 Mar 2017 12:16:36 +0200 Subject: [PATCH 1/2] add scripts option(custom commands) example to use: 1. Go test with custom params or other test framework like ginkgo 2. Fronted tools like grunt 3. Other custom commands --- cmd/bee.go | 1 + cmd/commands/scripts/scripts.go | 44 +++++++++++++++++++++++++++++++++ config/conf.go | 5 ++-- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 cmd/commands/scripts/scripts.go diff --git a/cmd/bee.go b/cmd/bee.go index 93a75cf..4f72d51 100644 --- a/cmd/bee.go +++ b/cmd/bee.go @@ -29,6 +29,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" ) diff --git a/cmd/commands/scripts/scripts.go b/cmd/commands/scripts/scripts.go new file mode 100644 index 0000000..b5576c5 --- /dev/null +++ b/cmd/commands/scripts/scripts.go @@ -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 +} diff --git a/config/conf.go b/config/conf.go index 2ed07ae..4277a24 100644 --- a/config/conf.go +++ b/config/conf.go @@ -79,8 +79,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() { From 6394f3f80a8d20919fd51d9db61fe03fff518da7 Mon Sep 17 00:00:00 2001 From: Faissal Elamraoui Date: Sun, 12 Mar 2017 23:42:37 +0000 Subject: [PATCH 2/2] Fixes desktop notificator for Windows and Linux --- utils/notification.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/utils/notification.go b/utils/notification.go index 1f5d124..b19b49f 100644 --- a/utils/notification.go +++ b/utils/notification.go @@ -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 import ( @@ -21,9 +34,9 @@ func Notify(text, title string) { case "darwin": osxNotify(text, title) case "linux": - windowsNotify(text, title) - case "windows": linuxNotify(text, title) + case "windows": + windowsNotify(text, title) } } @@ -45,7 +58,7 @@ func windowsNotify(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 {