Files
larksuite-cli/shortcuts/task/task_comment.go
evandance 8c3cba17b2 feat(task): emit typed error envelopes across the task domain (#1231)
Task commands now return structured, typed errors instead of the legacy
exit-code envelope: every failure carries a stable category, subtype, and
recovery hint, so callers can branch on the error class instead of parsing
messages. Exit codes derive from the error category — input validation exits 2,
a permission denial exits 3, other API errors exit 1.

Batch operations (adding tasks to a tasklist, creating a tasklist with tasks)
now report partial failure honestly: the per-item successes and failures stay
on stdout and the command exits non-zero instead of masking failures as a
success.
2026-06-05 22:30:45 +08:00

72 lines
1.8 KiB
Go

// Copyright (c) 2026 Lark Technologies Pte. Ltd.
// SPDX-License-Identifier: MIT
package task
import (
"context"
"fmt"
"io"
"net/http"
"github.com/larksuite/cli/shortcuts/common"
)
var CommentTask = common.Shortcut{
Service: "task",
Command: "+comment",
Description: "add a comment to a task",
Risk: "write",
Scopes: []string{"task:comment:write"},
AuthTypes: []string{"user", "bot"},
HasFormat: true,
Flags: []common.Flag{
{Name: "task-id", Desc: "task id", Required: true},
{Name: "content", Desc: "comment content", Required: true},
},
DryRun: func(ctx context.Context, runtime *common.RuntimeContext) *common.DryRunAPI {
body := map[string]interface{}{
"content": runtime.Str("content"),
"resource_id": runtime.Str("task-id"),
"resource_type": "task",
}
return common.NewDryRunAPI().
POST("/open-apis/task/v2/comments").
Params(map[string]interface{}{"user_id_type": "open_id"}).
Body(body)
},
Execute: func(ctx context.Context, runtime *common.RuntimeContext) error {
body := map[string]interface{}{
"content": runtime.Str("content"),
"resource_id": runtime.Str("task-id"),
"resource_type": "task",
}
params := map[string]interface{}{"user_id_type": "open_id"}
data, err := callTaskAPITyped(runtime, http.MethodPost, "/open-apis/task/v2/comments", params, body)
if err != nil {
return err
}
comment, _ := data["comment"].(map[string]interface{})
id, _ := comment["id"].(string)
// Standardized write output: return resource identifiers
outData := map[string]interface{}{
"id": id,
}
runtime.OutFormat(outData, nil, func(w io.Writer) {
fmt.Fprintf(w, "✅ Comment added successfully!\n")
if id != "" {
fmt.Fprintf(w, "Comment ID: %s\n", id)
}
})
return nil
},
}