mirror of
https://github.com/larksuite/cli.git
synced 2026-07-08 10:08:02 +08:00
Add 8 new shortcut commands under `lark-cli apps`: Plugin package management (aligned with fullstack-cli): - +plugin-install: download tgz, extract to node_modules, update package.json - +plugin-uninstall: remove from node_modules and package.json actionPlugins - +plugin-list: list declared plugins with installation status Plugin instance CRUD (aligned with feida-ai): - +plugin-instance-create: validate + write capability JSON with formValue validation - +plugin-instance-update: merge mutable fields, re-validate formValue - +plugin-instance-delete: idempotent file removal - +plugin-instance-get: read capability JSON - +plugin-instance-list: scan capabilities directory Shared infrastructure (plugin_common.go): - 4-level capabilities dir resolution (flag → env → .env.local MIAODA_APP_TYPE → detection) - formValue validation ported from feida-ai (5 rules: forbidden Handlebars, paramsSchema type constraints, input ref existence, unconsumed params, array double-wrap auto-fix) - tgz extraction with path traversal protection - package.json actionPlugins management - Install version check with mismatch warnings
74 lines
2.3 KiB
Go
74 lines
2.3 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package apps
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/larksuite/cli/shortcuts/common"
|
|
)
|
|
|
|
// AppsPluginInstanceDelete deletes a plugin instance (capability JSON file).
|
|
// The operation is idempotent: deleting a non-existent instance is not an error.
|
|
var AppsPluginInstanceDelete = common.Shortcut{
|
|
Service: appsService,
|
|
Command: "+plugin-instance-delete",
|
|
Description: "Delete a plugin instance",
|
|
Risk: "write",
|
|
Flags: []common.Flag{
|
|
{Name: "id", Desc: "instance id", Required: true},
|
|
{Name: "project-path", Desc: "project root path (defaults to current directory)"},
|
|
{Name: "capabilities-dir", Desc: "explicit capabilities directory (relative to project or absolute)"},
|
|
},
|
|
DryRun: func(ctx context.Context, rctx *common.RuntimeContext) *common.DryRunAPI {
|
|
id := strings.TrimSpace(rctx.Str("id"))
|
|
return common.NewDryRunAPI().
|
|
Desc("Delete plugin instance (remove capability JSON)").
|
|
Set("action", "delete").
|
|
Set("id", id).
|
|
Set("target", fmt.Sprintf("<capabilities_dir>/%s.json", id))
|
|
},
|
|
Validate: func(ctx context.Context, rctx *common.RuntimeContext) error {
|
|
if strings.TrimSpace(rctx.Str("id")) == "" {
|
|
return appsValidationParamError("--id", "--id is required")
|
|
}
|
|
projectPath, err := pluginResolveProjectPath(rctx.Str("project-path"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return pluginCheckProjectDir(projectPath)
|
|
},
|
|
Execute: func(ctx context.Context, rctx *common.RuntimeContext) error {
|
|
id := strings.TrimSpace(rctx.Str("id"))
|
|
projectPath, err := pluginResolveProjectPath(rctx.Str("project-path"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
capDir, err := pluginResolveCapDir(projectPath, rctx.Str("capabilities-dir"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
capPath := filepath.Join(capDir, id+".json")
|
|
if err := os.Remove(capPath); err != nil && !os.IsNotExist(err) { //nolint:forbidigo // shortcuts cannot import internal/vfs; local file delete.
|
|
return appsFileIOError(err, "cannot delete %s", capPath)
|
|
}
|
|
|
|
result := map[string]interface{}{
|
|
"id": id,
|
|
"deleted": true,
|
|
}
|
|
rctx.OutFormat(result, nil, func(w io.Writer) {
|
|
fmt.Fprintf(w, "✓ Plugin instance deleted: %s\n", id)
|
|
})
|
|
return nil
|
|
},
|
|
}
|