-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
76 lines (62 loc) · 1.52 KB
/
main.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
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
)
const VERSION = "v0.1.1"
var rootCmd = &cobra.Command{
Use: "sn",
Short: "Simple notifier",
Run: func(cmd *cobra.Command, args []string) {
locationStr, err := cmd.Flags().GetString("location")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
messageStr, err := cmd.Flags().GetString("message")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
cfg, err := LoadConfig()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
for k, v := range cfg.Locations {
if strings.ToLower(k) == strings.ToLower(locationStr) {
if strings.ToLower(v.Type) == strings.ToLower("discord") {
if err := SendDiscordMessage(v.Webhook, v.BotName, messageStr); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
return
}
}
fmt.Printf("Location %v not found !\n", locationStr)
},
}
var versionCmd = &cobra.Command{
Use: "version",
Short: "Display the version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Simple-notifier by Oxodao")
fmt.Println("https://github.com/oxodao/simple-notifier")
fmt.Println()
fmt.Println("Version " + VERSION)
},
}
func main() {
rootCmd.Flags().StringP("location", "l", "", "The location to send the message to")
rootCmd.Flags().StringP("message", "m", "", "The message to send")
rootCmd.MarkFlagRequired("location")
rootCmd.MarkFlagRequired("message")
rootCmd.AddCommand(versionCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}