mirror of
https://github.com/larksuite/cli.git
synced 2026-07-06 16:18:05 +08:00
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.
41 lines
1.2 KiB
Go
41 lines
1.2 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 SubscribeTaskEvent = common.Shortcut{
|
|
Service: "task",
|
|
Command: "+subscribe-event",
|
|
Description: "subscribe to task events",
|
|
Risk: "write",
|
|
Scopes: []string{"task:task:read"},
|
|
AuthTypes: []string{"user", "bot"},
|
|
HasFormat: true,
|
|
DryRun: func(ctx context.Context, runtime *common.RuntimeContext) *common.DryRunAPI {
|
|
return common.NewDryRunAPI().
|
|
POST("/open-apis/task/v2/task_v2/task_subscription").
|
|
Params(map[string]interface{}{"user_id_type": "open_id"})
|
|
},
|
|
Execute: func(ctx context.Context, runtime *common.RuntimeContext) error {
|
|
params := map[string]interface{}{"user_id_type": "open_id"}
|
|
if _, err := callTaskAPITyped(runtime, http.MethodPost, "/open-apis/task/v2/task_v2/task_subscription", params, nil); err != nil {
|
|
return err
|
|
}
|
|
|
|
outData := map[string]interface{}{"ok": true}
|
|
runtime.OutFormat(outData, nil, func(w io.Writer) {
|
|
fmt.Fprintln(w, "✅ Task event subscription created successfully!")
|
|
})
|
|
return nil
|
|
},
|
|
}
|