forked from sachaos/todoist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modify.go
58 lines (47 loc) · 1.16 KB
/
modify.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
package main
import (
"context"
"strings"
"github.com/sachaos/todoist/lib"
"github.com/urfave/cli/v2"
)
func Modify(c *cli.Context) error {
client := GetClient(c)
if !c.Args().Present() {
return CommandFailed
}
var err error
item_id, err := client.CompleteItemIDByPrefix(c.Args().First())
if err != nil {
return err
}
item := client.Store.FindItem(item_id)
if item == nil {
return IdNotFound
}
item.Content = c.String("content")
item.Priority = priorityMapping[c.Int("priority")]
item.LabelNames = func(str string) []string {
stringNames := strings.Split(str, ",")
names := []string{}
for _, stringName := range stringNames {
names = append(names, stringName)
}
return names
}(c.String("label-names"))
item.Due = &todoist.Due{String: c.String("date")}
projectID := c.String("project-id")
if projectID == "" {
projectID = client.Store.Projects.GetIDByName(c.String("project-name"))
}
if !c.Args().Present() {
return CommandFailed
}
if err := client.UpdateItem(context.Background(), *item); err != nil {
return err
}
if err := client.MoveItem(context.Background(), item, projectID); err != nil {
return err
}
return Sync(c)
}