Skip to content

Commit

Permalink
add item complete command
Browse files Browse the repository at this point in the history
  • Loading branch information
kobtea committed Feb 21, 2017
1 parent 77d01ec commit a324f52
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions cmd/todoist/cmd/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,46 @@ var itemAddCmd = &cobra.Command{
})
syncedItem := items[len(items)-1]
relations := client.Relation.Items([]todoist.Item{syncedItem})
fmt.Println("Successful addition of an item.")
fmt.Println(util.ItemTableString([]todoist.Item{syncedItem}, relations))
return nil
},
}

var itemCompleteCmd = &cobra.Command{
Use: "complete",
Short: "complete items",
RunE: func(cmd *cobra.Command, args []string) error {
var ids []todoist.ID
for _, s := range args {
id, err := todoist.NewID(s)
if err != nil {
return fmt.Errorf("Invalid ID: %s", s)
}
ids = append(ids, id)
}
client, err := newClient()
if err != nil {
return err
}
if err = client.Item.Complete(ids, true); err != nil {
return err
}
ctx := context.Background()
if err = client.Commit(ctx); err != nil {
return err
}
if err = client.FullSync(ctx, []todoist.Command{}); err != nil {
return err
}
fmt.Println("Successful completion of item(s).")
return nil
},
}

func init() {
RootCmd.AddCommand(itemCmd)
itemCmd.AddCommand(itemListCmd)
itemCmd.AddCommand(itemAddCmd)
itemCmd.AddCommand(itemCompleteCmd)
}
2 changes: 1 addition & 1 deletion todoist/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (i ID) MarshalJSON() ([]byte, error) {
if IsTempID(i) {
s = `"` + s + `"`
}
if s == "0" {
if s == "0" || s == "" {
s = "null"
}
return []byte(s), nil
Expand Down

0 comments on commit a324f52

Please sign in to comment.