-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (42 loc) · 1.17 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
package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
)
func checkErrorFatal(err error) {
if err != nil {
log.Fatalln(err)
}
}
func main() {
cacheFlags := flag.NewFlagSet("cache", flag.ExitOnError)
cacheDepsArg := cacheFlags.String("deps", "", "List of files on which cache depends (space-separated)")
notifyFlags := flag.NewFlagSet("notify", flag.ExitOnError)
notifyDiscordArg := notifyFlags.Bool("discord", false, `Send notification to Discord. (requires: discord_webhook_token, discord_webhook_id)`)
notifySlackArg := notifyFlags.Bool("slack", false, `Send notification to Slack. (requires: slack_webhook_token)`)
if len(os.Args) < 2 {
log.Fatalln("expected 'cache' or 'notify' subcommands")
}
switch os.Args[1] {
case "cache":
cacheFlags.Parse(os.Args[2:])
cacheDeps := strings.Fields(*cacheDepsArg)
if len(cacheDeps) <= 0 {
log.Fatalln("cannot indentify cache: no dependencies given (--deps)")
}
rebuildCache(cacheDeps)
case "notify":
notifyFlags.Parse(os.Args[2:])
switch {
case *notifyDiscordArg:
discord.notify()
case *notifySlackArg:
slack.notify()
}
default:
log.Fatalln(fmt.Sprintf("unexpected subcommand: %s", os.Args[1]))
}
}