forked from sachaos/todoist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.go
56 lines (47 loc) · 1.4 KB
/
list.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 (
"github.com/sachaos/todoist/lib"
"github.com/urfave/cli"
)
func List(c *cli.Context) error {
client := GetClient(c)
colorList := ColorList()
projectsCount := len(client.Store.Projects)
projectIds := make([]int, projectsCount, projectsCount)
for i, project := range client.Store.Projects {
projectIds[i] = project.GetID()
}
projectColorHash := GenerateColorHash(projectIds, colorList)
ex := Filter(c.String("filter"))
itemList := make([][]string, 0, len(client.Store.ItemOrders))
for _, itemOrder := range client.Store.ItemOrders {
item := itemOrder.Data.(todoist.Item)
r, err := Eval(ex, item, client.Store.Projects, client.Store.Labels)
if err != nil {
return err
}
if !r || item.Checked == 1 {
continue
}
projectID := c.Int("project-id")
if projectID != 0 && item.ProjectID != projectID {
continue
}
itemList = append(itemList, []string{
IdFormat(item),
PriorityFormat(item.Priority),
DueDateFormat(item.DateTime(), item.AllDay),
ProjectFormat(item.ProjectID, client.Store.Projects, projectColorHash, c),
item.LabelsString(client.Store.Labels),
ContentPrefix(client.Store.Items, item, c) + ContentFormat(item),
})
}
defer writer.Flush()
if c.GlobalBool("header") {
writer.Write([]string{"ID", "Priority", "DueDate", "Project", "Labels", "Content"})
}
for _, strings := range itemList {
writer.Write(strings)
}
return nil
}