-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.go
More file actions
48 lines (37 loc) · 821 Bytes
/
cli.go
File metadata and controls
48 lines (37 loc) · 821 Bytes
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
package main
import (
"errors"
"fmt"
"time"
"github.com/urfave/cli/v2"
)
type cliContext struct {
*cli.Context
}
func (ctx *cliContext) makeTags() (taskWarriorTags, error) {
slice := ctx.StringSlice("tag")
if len(slice) == 0 {
return nil, errors.New("at least one tag is required")
}
return taskWarriorTags(slice), nil
}
func (ctx *cliContext) getTimeWindow() (time.Time, time.Time) {
t1 := time.Now().Add(-time.Hour * 24)
t2 := t1.Add(ctx.Duration("duration"))
return t1, t2
}
func (ctx *cliContext) run() error {
tw, err := findTaskwarrior()
if err != nil {
return err
}
cal, err := getCalendarClient()
if err != nil {
return fmt.Errorf("Trouble contacting google calendar: %w", err)
}
m := newMerge(ctx, tw, cal)
if err := m.run(); err != nil {
m.log.Error(err)
}
return nil
}