/
gcal.go
51 lines (41 loc) · 981 Bytes
/
gcal.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
package main
import (
"context"
"fmt"
"os"
"github.com/spf13/pflag"
"google.golang.org/api/calendar/v3"
"google.golang.org/api/option"
"github.com/leftmike/gcal/oauth2gcp"
"github.com/leftmike/gcal/tool"
)
var (
gcal = tool.Tool{
Runners: map[string]tool.ToolRunner{
"list": tool.ToolRunner{
Syntax: "list [<from> [<to>]]",
Usage: "list calendar events",
Runner: tool.FlagsCommand(listEvents),
},
},
}
)
func calendarService() *calendar.Service {
ctx := context.Background()
client, err := oauth2gcp.GetClient(ctx, ".", calendar.CalendarReadonlyScope)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
svc, err := calendar.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
fmt.Fprintf(os.Stderr, "unable to retrieve calendar service: %s", err)
os.Exit(1)
}
return svc
}
func main() {
fs := pflag.NewFlagSet(os.Args[0], pflag.ExitOnError)
fs.SortFlags = true
gcal.Run(os.Args[0], fs, os.Args[1:])
}