forked from ForceCLI/force
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.go
65 lines (55 loc) · 1.37 KB
/
notify.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"fmt"
"strconv"
"github.com/ViViDboarder/gotifier"
)
var cmdNotifySet = &Command{
Run: notifySet,
Usage: "notify (true | false)",
Short: "Should notifications be used",
Long: `
Determines if notifications should be used
`,
}
func notifySet(cmd *Command, args []string) {
var err error
shouldNotify := true
if len(args) == 0 {
shouldNotify = getShouldNotify()
fmt.Println("Show notifications: " + strconv.FormatBool(shouldNotify))
} else if len(args) == 1 {
shouldNotify, err = strconv.ParseBool(args[0])
if err != nil {
fmt.Println("Expecting a boolean parameter.")
}
} else {
fmt.Println("Expecting only one parameter. true/false")
}
setShouldNotify(shouldNotify)
}
func setShouldNotify(shouldNotify bool) {
// Set config
Config.Save("notifications", "shouldNotify", strconv.FormatBool(shouldNotify))
}
func getShouldNotify() bool {
shouldNotify := false
notifStr, err := Config.Load("notifications", "shouldNotify")
if err == nil {
shouldNotify, err = strconv.ParseBool(notifStr)
}
return shouldNotify
}
func notify(method string, message string) {
shouldNotify := getShouldNotify()
if shouldNotify {
gotifier.Notification{Title: "Force Cli", Subtitle: method, Message: message}.Push()
}
}
func notifySuccess(method string, success bool) {
if success {
notify(method, "SUCCESS")
} else {
notify(method, "FAILURE")
}
}