forked from sachaos/todoist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow.go
53 lines (44 loc) · 1.24 KB
/
show.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
package main
import (
"strconv"
"github.com/pkg/browser"
"github.com/sachaos/todoist/lib"
"github.com/urfave/cli"
)
func Show(c *cli.Context) error {
client := GetClient(c)
item_id, err := strconv.Atoi(c.Args().First())
if err != nil {
return CommandFailed
}
idCarrier, err := todoist.SearchByID(client.Store.Items, item_id)
if err != nil {
return IdNotFound
}
item := idCarrier.(todoist.Item)
colorList := ColorList()
var projectIds []int
for _, project := range client.Store.Projects {
projectIds = append(projectIds, project.GetID())
}
projectColorHash := GenerateColorHash(projectIds, colorList)
records := [][]string{
[]string{"ID", IdFormat(item)},
[]string{"Content", ContentFormat(item)},
[]string{"Project", ProjectFormat(item.ProjectID, client.Store.Projects, projectColorHash, c)},
[]string{"Labels", item.LabelsString(client.Store.Labels)},
[]string{"Priority", PriorityFormat(item.Priority)},
[]string{"DueDate", DueDateFormat(item.DateTime(), item.AllDay)},
[]string{"URL", todoist.GetContentURL(item)},
}
defer writer.Flush()
for _, record := range records {
writer.Write(record)
}
if todoist.HasURL(item) {
if c.Bool("browse") {
browser.OpenURL(todoist.GetContentURL(item))
}
}
return nil
}