Skip to content

Commit 70a0c55

Browse files
committed
Add task kind flag for note/checklist creation
1 parent a67cf25 commit 70a0c55

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

internal/cli/tasks.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package cli
22

33
import (
44
"context"
5+
"fmt"
6+
"strings"
57

68
"github.com/apktdev/ticktick-cli/internal/ticktick"
79
"github.com/spf13/cobra"
@@ -40,7 +42,7 @@ func (a *app) newTasksCmd() *cobra.Command {
4042
},
4143
}
4244

43-
var addProjectID, addTitle, addContent, addDesc, addStart, addDue, addTimeZone, addRepeat string
45+
var addProjectID, addTitle, addContent, addDesc, addStart, addDue, addTimeZone, addRepeat, addKind string
4446
var addPriority int
4547
var addAllDay bool
4648
var addReminders []string
@@ -62,6 +64,10 @@ func (a *app) newTasksCmd() *cobra.Command {
6264
if err != nil {
6365
return err
6466
}
67+
kind, err := normalizeTaskKind(addKind)
68+
if err != nil {
69+
return err
70+
}
6571
created, err := a.client.CreateTask(context.Background(), ticktick.Task{
6672
ProjectID: addProjectID,
6773
Title: addTitle,
@@ -74,6 +80,7 @@ func (a *app) newTasksCmd() *cobra.Command {
7480
Reminders: addReminders,
7581
Priority: addPriority,
7682
IsAllDay: addAllDay,
83+
Kind: kind,
7784
})
7885
if err != nil {
7986
return err
@@ -89,11 +96,12 @@ func (a *app) newTasksCmd() *cobra.Command {
8996
add.Flags().StringVar(&addDue, "due", "", "Due date (RFC3339 or YYYY-MM-DD)")
9097
add.Flags().StringVar(&addTimeZone, "time-zone", "", "IANA timezone (e.g. America/Los_Angeles)")
9198
add.Flags().StringVar(&addRepeat, "repeat", "", "Recurring rule (e.g. RRULE:FREQ=DAILY;INTERVAL=1)")
99+
add.Flags().StringVar(&addKind, "kind", "", "Item kind: TEXT, NOTE, CHECKLIST")
92100
add.Flags().StringSliceVar(&addReminders, "reminder", nil, "Reminder trigger(s), repeatable")
93101
add.Flags().BoolVar(&addAllDay, "all-day", false, "Mark task as all-day")
94102
add.Flags().IntVar(&addPriority, "priority", 0, "Priority: 0 none, 1 low, 3 medium, 5 high")
95103

96-
var updateProjectID, updateTitle, updateContent, updateDesc, updateStart, updateDue, updateTimeZone, updateRepeat string
104+
var updateProjectID, updateTitle, updateContent, updateDesc, updateStart, updateDue, updateTimeZone, updateRepeat, updateKind string
97105
var updatePriority int
98106
var updateAllDay bool
99107
var updateReminders []string
@@ -113,6 +121,10 @@ func (a *app) newTasksCmd() *cobra.Command {
113121
if err != nil {
114122
return err
115123
}
124+
kind, err := normalizeTaskKind(updateKind)
125+
if err != nil {
126+
return err
127+
}
116128
updated, err := a.client.UpdateTask(context.Background(), args[0], ticktick.Task{
117129
ID: args[0],
118130
ProjectID: updateProjectID,
@@ -126,6 +138,7 @@ func (a *app) newTasksCmd() *cobra.Command {
126138
Reminders: updateReminders,
127139
Priority: updatePriority,
128140
IsAllDay: updateAllDay,
141+
Kind: kind,
129142
})
130143
if err != nil {
131144
return err
@@ -141,6 +154,7 @@ func (a *app) newTasksCmd() *cobra.Command {
141154
update.Flags().StringVar(&updateDue, "due", "", "Due date (RFC3339 or YYYY-MM-DD)")
142155
update.Flags().StringVar(&updateTimeZone, "time-zone", "", "IANA timezone (e.g. America/Los_Angeles)")
143156
update.Flags().StringVar(&updateRepeat, "repeat", "", "Recurring rule (e.g. RRULE:FREQ=DAILY;INTERVAL=1)")
157+
update.Flags().StringVar(&updateKind, "kind", "", "Item kind: TEXT, NOTE, CHECKLIST")
144158
update.Flags().StringSliceVar(&updateReminders, "reminder", nil, "Reminder trigger(s), repeatable")
145159
update.Flags().BoolVar(&updateAllDay, "all-day", false, "Mark task as all-day")
146160
update.Flags().IntVar(&updatePriority, "priority", 0, "Priority: 0 none, 1 low, 3 medium, 5 high")
@@ -172,3 +186,16 @@ func (a *app) newTasksCmd() *cobra.Command {
172186
tasks.AddCommand(list, get, add, update, complete, deleteCmd)
173187
return tasks
174188
}
189+
190+
func normalizeTaskKind(kind string) (string, error) {
191+
if kind == "" {
192+
return "", nil
193+
}
194+
v := strings.ToUpper(strings.TrimSpace(kind))
195+
switch v {
196+
case "TEXT", "NOTE", "CHECKLIST":
197+
return v, nil
198+
default:
199+
return "", fmt.Errorf("invalid --kind %q; use TEXT, NOTE, or CHECKLIST", kind)
200+
}
201+
}

0 commit comments

Comments
 (0)