Skip to content

Commit

Permalink
Merge pull request #128 from resurtm/ticket-127-2
Browse files Browse the repository at this point in the history
fixes #127: ability to disable desktop notifications
  • Loading branch information
ibash authored Oct 26, 2017
2 parents 0124369 + 8d93826 commit cafe2ce
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Options
--certFile value TLS Certificate
--keyFile value TLS Certificate Key
--logPrefix value Setup custom log prefix
--notifications enable desktop notifications
--help, -h show help
--version, -v print the version
```
Expand Down
39 changes: 26 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import (
)

var (
startTime = time.Now()
logger = log.New(os.Stdout, "[gin] ", 0)
immediate = false
buildError error
colorGreen = string([]byte{27, 91, 57, 55, 59, 51, 50, 59, 49, 109})
colorRed = string([]byte{27, 91, 57, 55, 59, 51, 49, 59, 49, 109})
colorReset = string([]byte{27, 91, 48, 109})
notifier = notificator.New(notificator.Options{AppName: "Gin Build"})
startTime = time.Now()
logger = log.New(os.Stdout, "[gin] ", 0)
immediate = false
buildError error
colorGreen = string([]byte{27, 91, 57, 55, 59, 51, 50, 59, 49, 109})
colorRed = string([]byte{27, 91, 57, 55, 59, 51, 49, 59, 49, 109})
colorReset = string([]byte{27, 91, 48, 109})
notifier = notificator.New(notificator.Options{AppName: "Gin Build"})
notifications = false
)

func main() {
Expand Down Expand Up @@ -115,6 +116,11 @@ func main() {
Usage: "Log prefix",
Value: "gin",
},
cli.BoolFlag{
Name: "notifications",
EnvVar: "GIN_NOTIFICATIONS",
Usage: "Enables desktop notifications",
},
}
app.Commands = []cli.Command{
{
Expand Down Expand Up @@ -143,6 +149,7 @@ func MainAction(c *cli.Context) {
keyFile := c.GlobalString("keyFile")
certFile := c.GlobalString("certFile")
logPrefix := c.GlobalString("logPrefix")
notifications = c.GlobalBool("notifications")

logger.SetPrefix(fmt.Sprintf("[%s] ", logPrefix))

Expand Down Expand Up @@ -221,24 +228,30 @@ func EnvAction(c *cli.Context) {
func build(builder gin.Builder, runner gin.Runner, logger *log.Logger) {
logger.Println("Building...")

notifier.Push("Build Started!", "Building "+builder.Binary()+"...", "", notificator.UR_NORMAL)
if notifications {
notifier.Push("Build Started!", "Building "+builder.Binary()+"...", "", notificator.UR_NORMAL)
}
err := builder.Build()
if err != nil {
buildError = err
logger.Printf("%sBuild failed%s\n", colorRed, colorReset)
fmt.Println(builder.Errors())
buildErrors := strings.Split(builder.Errors(), "\n")
if err := notifier.Push("Build FAILED!", buildErrors[1], "", notificator.UR_CRITICAL); err != nil {
logger.Println("Notification send failed")
if notifications {
if err := notifier.Push("Build FAILED!", buildErrors[1], "", notificator.UR_CRITICAL); err != nil {
logger.Println("Notification send failed")
}
}
} else {
buildError = nil
logger.Printf("%sBuild finished%s\n", colorGreen, colorReset)
if immediate {
runner.Run()
}
if err := notifier.Push("Build Succeded", "Build Finished!", "", notificator.UR_CRITICAL); err != nil {
logger.Println("Notification send failed")
if notifications {
if err := notifier.Push("Build Succeded", "Build Finished!", "", notificator.UR_CRITICAL); err != nil {
logger.Println("Notification send failed")
}
}
}

Expand Down

0 comments on commit cafe2ce

Please sign in to comment.