Skip to content

Commit cafe2ce

Browse files
authored
Merge pull request #128 from resurtm/ticket-127-2
fixes #127: ability to disable desktop notifications
2 parents 0124369 + 8d93826 commit cafe2ce

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Options
4444
--certFile value TLS Certificate
4545
--keyFile value TLS Certificate Key
4646
--logPrefix value Setup custom log prefix
47+
--notifications enable desktop notifications
4748
--help, -h show help
4849
--version, -v print the version
4950
```

main.go

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ import (
2121
)
2222

2323
var (
24-
startTime = time.Now()
25-
logger = log.New(os.Stdout, "[gin] ", 0)
26-
immediate = false
27-
buildError error
28-
colorGreen = string([]byte{27, 91, 57, 55, 59, 51, 50, 59, 49, 109})
29-
colorRed = string([]byte{27, 91, 57, 55, 59, 51, 49, 59, 49, 109})
30-
colorReset = string([]byte{27, 91, 48, 109})
31-
notifier = notificator.New(notificator.Options{AppName: "Gin Build"})
24+
startTime = time.Now()
25+
logger = log.New(os.Stdout, "[gin] ", 0)
26+
immediate = false
27+
buildError error
28+
colorGreen = string([]byte{27, 91, 57, 55, 59, 51, 50, 59, 49, 109})
29+
colorRed = string([]byte{27, 91, 57, 55, 59, 51, 49, 59, 49, 109})
30+
colorReset = string([]byte{27, 91, 48, 109})
31+
notifier = notificator.New(notificator.Options{AppName: "Gin Build"})
32+
notifications = false
3233
)
3334

3435
func main() {
@@ -115,6 +116,11 @@ func main() {
115116
Usage: "Log prefix",
116117
Value: "gin",
117118
},
119+
cli.BoolFlag{
120+
Name: "notifications",
121+
EnvVar: "GIN_NOTIFICATIONS",
122+
Usage: "Enables desktop notifications",
123+
},
118124
}
119125
app.Commands = []cli.Command{
120126
{
@@ -143,6 +149,7 @@ func MainAction(c *cli.Context) {
143149
keyFile := c.GlobalString("keyFile")
144150
certFile := c.GlobalString("certFile")
145151
logPrefix := c.GlobalString("logPrefix")
152+
notifications = c.GlobalBool("notifications")
146153

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

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

224-
notifier.Push("Build Started!", "Building "+builder.Binary()+"...", "", notificator.UR_NORMAL)
231+
if notifications {
232+
notifier.Push("Build Started!", "Building "+builder.Binary()+"...", "", notificator.UR_NORMAL)
233+
}
225234
err := builder.Build()
226235
if err != nil {
227236
buildError = err
228237
logger.Printf("%sBuild failed%s\n", colorRed, colorReset)
229238
fmt.Println(builder.Errors())
230239
buildErrors := strings.Split(builder.Errors(), "\n")
231-
if err := notifier.Push("Build FAILED!", buildErrors[1], "", notificator.UR_CRITICAL); err != nil {
232-
logger.Println("Notification send failed")
240+
if notifications {
241+
if err := notifier.Push("Build FAILED!", buildErrors[1], "", notificator.UR_CRITICAL); err != nil {
242+
logger.Println("Notification send failed")
243+
}
233244
}
234245
} else {
235246
buildError = nil
236247
logger.Printf("%sBuild finished%s\n", colorGreen, colorReset)
237248
if immediate {
238249
runner.Run()
239250
}
240-
if err := notifier.Push("Build Succeded", "Build Finished!", "", notificator.UR_CRITICAL); err != nil {
241-
logger.Println("Notification send failed")
251+
if notifications {
252+
if err := notifier.Push("Build Succeded", "Build Finished!", "", notificator.UR_CRITICAL); err != nil {
253+
logger.Println("Notification send failed")
254+
}
242255
}
243256
}
244257

0 commit comments

Comments
 (0)