MCPcopy Index your code
hub / github.com/larksuite/cli / buildTaskCreateBody

Function buildTaskCreateBody

shortcuts/task/shortcuts.go:103–160  ·  view source on GitHub ↗
(runtime *common.RuntimeContext)

Source from the content-addressed store, hash-verified

101}
102
103func buildTaskCreateBody(runtime *common.RuntimeContext) (map[string]interface{}, error) {
104 body := make(map[string]interface{})
105
106 // Handle generic JSON payload if provided
107 if dataStr := runtime.Str("data"); dataStr != "" {
108 if err := json.Unmarshal([]byte(dataStr), &body); err != nil {
109 return nil, errs.NewValidationError(errs.SubtypeInvalidArgument, "--data must be a valid JSON object: %v", err).WithParam("--data")
110 }
111 }
112
113 // Explicit flags override generic data
114 if summary := runtime.Str("summary"); summary != "" {
115 body["summary"] = summary
116 }
117
118 if desc := runtime.Str("description"); desc != "" {
119 body["description"] = desc
120 }
121
122 var members []map[string]interface{}
123 if assignee := runtime.Str("assignee"); assignee != "" {
124 members = append(members, buildTaskMember(assignee, "assignee"))
125 }
126 if follower := runtime.Str("follower"); follower != "" {
127 members = append(members, buildTaskMember(follower, "follower"))
128 }
129 if len(members) > 0 {
130 body["members"] = members
131 }
132
133 if tasklistId := runtime.Str("tasklist-id"); tasklistId != "" {
134 guid := extractTasklistGuid(tasklistId)
135 body["tasklists"] = []map[string]interface{}{
136 {
137 "tasklist_guid": guid,
138 },
139 }
140 }
141
142 if dueStr := runtime.Str("due"); dueStr != "" {
143 dueObj, err := parseTaskTime(dueStr)
144 if err != nil {
145 return nil, errs.NewValidationError(errs.SubtypeInvalidArgument, "failed to parse due time: %v", err).WithParam("--due")
146 }
147 body["due"] = dueObj
148 }
149
150 if idempotencyKey := runtime.Str("idempotency-key"); idempotencyKey != "" {
151 body["client_token"] = idempotencyKey
152 }
153
154 summary, _ := body["summary"].(string)
155 if strings.TrimSpace(summary) == "" {
156 return nil, errs.NewValidationError(errs.SubtypeInvalidArgument, "task summary is required").WithParam("--summary")
157 }
158
159 return body, nil
160}

Calls 6

NewValidationErrorFunction · 0.92
buildTaskMemberFunction · 0.85
extractTasklistGuidFunction · 0.85
parseTaskTimeFunction · 0.85
WithParamMethod · 0.80
StrMethod · 0.65