-
-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathprojects.go
48 lines (36 loc) · 1.05 KB
/
projects.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
package main
import (
todoist "github.com/sachaos/todoist/lib"
"github.com/urfave/cli/v2"
)
func traverseProjects(pjt *todoist.Project, f func(pjt *todoist.Project, depth int), depth int) {
f(pjt, depth)
if pjt.ChildProject != nil {
traverseProjects(pjt.ChildProject, f, depth+1)
}
if pjt.BrotherProject != nil {
traverseProjects(pjt.BrotherProject, f, depth)
}
}
func Projects(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)
itemList := [][]string{}
project := client.Store.RootProject
traverseProjects(project, func(pjt *todoist.Project, depth int) {
itemList = append(itemList, []string{IdFormat(pjt), ProjectFormat(pjt.ID, client.Store, projectColorHash, c)})
}, 0)
defer writer.Flush()
if c.Bool("header") {
writer.Write([]string{"ID", "Name"})
}
for _, strings := range itemList {
writer.Write(strings)
}
return nil
}