-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
62 lines (57 loc) · 1.35 KB
/
config.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
package main
import (
"fmt"
"os"
"strings"
"time"
log "github.com/sirupsen/logrus"
"github.com/docopt/docopt-go"
)
type Config struct {
Delay time.Duration
Source Source
SlackWebhook string
SlackChannel string
Debug bool
}
func getConfig() (Config, error) {
c := Config{}
args, err := docopt.Parse(usage, nil, true, Version, false)
if err != nil {
return c, err
}
if args["--list"].(bool) {
names := []string{}
for name, _ := range getSources() {
names = append(names, name)
}
fmt.Printf("Supported resort names: %s\n", strings.Join(names, ", "))
os.Exit(0)
}
c.Debug = args["--debug"].(bool)
if err != nil {
return c, err
}
if c.Debug {
log.SetLevel(log.DebugLevel)
}
c.Source, err = getSource(args["<resort>"].(string))
if err != nil {
return c, err
}
delaySpec := args["--delay"].(string)
c.Delay, err = time.ParseDuration(delaySpec)
if err != nil {
return c, fmt.Errorf("Invalid --delay: %s", err)
}
if c.Delay < minDelayTime {
log.Printf("Note: using minimum supported %s delay.", minDelayTime)
c.Delay = minDelayTime
}
c.SlackWebhook = os.Getenv("SLACK_WEBHOOK")
c.SlackChannel = os.Getenv("SLACK_CHANNEL")
if len(c.SlackWebhook) < 1 || len(c.SlackChannel) < 1 {
log.Debugf("Slack notifications disabled: SLACK_WEBHOOK and/or SLACK_CHANNEL environment variables not set")
}
return c, nil
}