-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (47 loc) · 1.4 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
package main
import (
"flag"
"fmt"
"os"
"github.com/google/subcommands"
"github.com/pkg/errors"
"golang.org/x/net/context"
"github.com/robertdolca/calendar-sync/clients/calendar"
"github.com/robertdolca/calendar-sync/clients/syncdb"
"github.com/robertdolca/calendar-sync/clients/tmanager"
"github.com/robertdolca/calendar-sync/clients/userinfo"
"github.com/robertdolca/calendar-sync/commands/auth"
"github.com/robertdolca/calendar-sync/commands/clear"
"github.com/robertdolca/calendar-sync/commands/list"
synccmd "github.com/robertdolca/calendar-sync/commands/sync"
)
func run() subcommands.ExitStatus {
tm, err := tmanager.New()
if err != nil {
fmt.Println(errors.Wrap(err, "failed to create token manager"))
return subcommands.ExitFailure
}
sdb, err := syncdb.New()
if err != nil {
fmt.Println(errors.Wrap(err, "failed to create sync records database"))
return subcommands.ExitFailure
}
defer func() {
err := sdb.Close()
if err != nil {
fmt.Println(errors.Wrap(err, "failed to close db connection"))
}
}()
ui := userinfo.New(tm)
cm := calendar.New(tm, ui, sdb)
subcommands.Register(subcommands.HelpCommand(), "")
subcommands.Register(auth.New(tm), "")
subcommands.Register(list.New(cm), "")
subcommands.Register(synccmd.New(cm), "")
subcommands.Register(clear.New(cm), "")
flag.Parse()
return subcommands.Execute(context.Background())
}
func main() {
os.Exit(int(run()))
}