-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (40 loc) · 976 Bytes
/
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"
"os"
"github.com/j0hax/gobrief/agenda"
"github.com/j0hax/gobrief/config"
)
func customUsage() {
out := flag.CommandLine.Output()
fmt.Fprintf(out, "Usage: %s [CALENDAR]\n", os.Args[0])
flag.PrintDefaults()
}
func main() {
cfg := config.LoadConfig()
flag.Usage = customUsage
list := flag.Bool("list", false, "list calendars")
add := flag.Bool("add", false, "add calendar sources in the pattern [NAME] [URL]")
del := flag.Bool("del", false, "remove calender by [NAME]")
nDays := flag.Int("days", cfg.Days, "number of days to look ahead")
flag.Parse()
if *list {
out := flag.CommandLine.Output()
cfg.ListCalendars(out)
os.Exit(0)
}
if *add {
cfg.AddCalendar(flag.Args()...)
cfg.SaveExit()
} else if *del {
cfg.DeleteCalendar(flag.Args()...)
cfg.SaveExit()
}
if len(flag.Args()) > 0 {
cfg.SelectCalendars(flag.Args()...)
}
cfg.Days = *nDays
a := agenda.NewAgenda(cfg)
a.PrettyPrint(os.Stdout)
}