Skip to content

Commit

Permalink
fix ItemClient#Complete
Browse files Browse the repository at this point in the history
  • Loading branch information
kobtea committed Sep 14, 2019
1 parent cff7de9 commit 8445c27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
16 changes: 11 additions & 5 deletions cmd/todoist/cmd/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"sort"
"strings"
"time"
)

// itemCmd represents the item command
Expand Down Expand Up @@ -280,11 +281,16 @@ var itemCompleteCmd = &cobra.Command{
Short: "complete items",
RunE: func(cmd *cobra.Command, args []string) error {
if err := util.AutoCommit(func(client todoist.Client, ctx context.Context) error {
return util.ProcessIDs(
args,
func(ids []todoist.ID) error {
return client.Item.Complete(ids, true)
})
if len(args) != 1 {
return fmt.Errorf("require one item id")
}
id, err := todoist.NewID(args[0])
if err != nil {
return err
}
// FIXME: support date_completed option
date := todoist.Time{time.Now().UTC()}
return client.Item.Complete(id, date, true)
}); err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions todoist/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (c *ItemClient) Move(projectItems map[ID][]ID, toProject ID) error {
return nil
}

func (c *ItemClient) Complete(ids []ID, forceHistory bool) error {
func (c *ItemClient) Complete(id ID, dateCompleted Time, forceHistory bool) error {
var fh int
if forceHistory {
fh = 1
Expand All @@ -119,8 +119,9 @@ func (c *ItemClient) Complete(ids []ID, forceHistory bool) error {
Type: "item_complete",
UUID: GenerateUUID(),
Args: map[string]interface{}{
"ids": ids,
"force_history": fh,
"id": id,
"date_completed": dateCompleted,
"force_history": fh,
},
}
c.queue = append(c.queue, command)
Expand Down

0 comments on commit 8445c27

Please sign in to comment.