-
-
Notifications
You must be signed in to change notification settings - Fork 105
/
completed.go
51 lines (40 loc) · 1.04 KB
/
completed.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"
todoist "github.com/sachaos/todoist/lib"
"github.com/urfave/cli/v2"
)
func CompletedList(c *cli.Context) error {
client := GetClient(c)
colorList := ColorList()
var projectIds []string
for _, project := range client.Store.Projects {
projectIds = append(projectIds, project.GetID())
}
projectColorHash := GenerateColorHash(projectIds, colorList)
ex := Filter(c.String("filter"))
var completed todoist.Completed
if err := client.CompletedAll(context.Background(), &completed); err != nil {
return err
}
defer writer.Flush()
if c.Bool("header") {
writer.Write([]string{"ID", "CompletedDate", "Project", "Content"})
}
for _, item := range completed.Items {
result, err := Eval(ex, item, client.Store.Projects, client.Store.Labels)
if err != nil {
return err
}
if !result {
continue
}
writer.Write([]string{
IdFormat(item),
CompletedDateFormat(item.DateTime()),
ProjectFormat(item.ProjectID, client.Store, projectColorHash, c),
ContentFormat(item),
})
}
return nil
}