forked from sachaos/todoist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompleted.go
60 lines (47 loc) · 1.17 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
52
53
54
55
56
57
58
59
60
package main
import (
"context"
"github.com/sachaos/todoist/lib"
"github.com/urfave/cli"
)
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"))
rawFilter := c.String("raw")
var completed todoist.Completed
if err := client.CompletedAll(context.Background(), &completed); err != nil {
return err
}
defer writer.Flush()
if c.GlobalBool("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
}
itemText := ""
if rawFilter == "true" {
itemText = item.GetContent()
} else {
itemText = ContentFormat(item)
}
writer.Write([]string{
IdFormat(item),
CompletedDateFormat(item.DateTime()),
ProjectFormat(item.ProjectID, client.Store, projectColorHash, c),
itemText,
})
}
return nil
}