Files
larksuite__cli/shortcuts/apps/shortcuts.go
chenxingyang1019 41692b7041 feat(apps): add cache debug commands (+cache-get/-delete/-clear) (#1896)
* feat(apps): add cache debug commands (+cache-get/-delete/-clear)

Add three apps-domain cache debug shortcuts for inspecting/clearing an app's
runtime cache:
- +cache-get: read a business key's value + metadata (hit/miss)
- +cache-delete: delete a single key (idempotent, write)
- +cache-clear: clear all cache in an environment (high-risk-write, --yes)

value renders raw on --format json, deserialized on --format pretty;
value_size_bytes is computed CLI-side; --environment auto-selects the branch
when omitted. Includes unit tests (hit/miss/dry-run/confirmation) and the
lark-apps cache skill reference.

* fix(apps): normalize cache numeric output fields and tidy comments

Follow-up hardening for the cache debug commands (+cache-get/-delete/-clear):

- Normalize ttl_ms / deleted_key_count via a new cacheInt() helper so
  --format json emits a stable JSON number (or null) regardless of whether
  the server sends the value as a number or a string. Aligns with the
  repo convention that numeric wire fields may arrive as strings; previously
  these were passed through raw, leaving the output type at the server's mercy.
- Add unit tests locking the string-wire -> JSON number contract for both
  cache-get ttl_ms and cache-delete deleted_key_count.
- Tidy two comments: soften cacheBool's speculative "historical wire form"
  claim to a defensive-tolerance note, and drop implementation jargon from
  cache-delete's risk-level rationale.
2026-07-31 14:13:56 +08:00

105 lines
2.9 KiB
Go

// Copyright (c) 2026 Lark Technologies Pte. Ltd.
// SPDX-License-Identifier: MIT
package apps
import "github.com/larksuite/cli/shortcuts/common"
// Shortcuts returns all apps domain shortcuts.
func Shortcuts() []common.Shortcut {
envSet := withExtraTips(AppsEnvVarSet, "Example: lark-cli apps +env-set --app-id <app_id> --environment online --key FOO --value <value> --yes")
envDelete := withExtraTips(AppsEnvVarDelete, "Tip: +env-delete is high-risk-write; only pass --yes after explicit confirmation.")
return []common.Shortcut{
AppsCreate,
AppsGet,
AppsUpdate,
AppsList,
AppsAccessScopeSet,
AppsAccessScopeGet,
AppsRoleList,
AppsRoleGet,
AppsRoleCreate,
AppsRoleUpdate,
AppsRoleDelete,
AppsRoleMemberList,
AppsRoleMemberAdd,
AppsRoleMemberRemove,
AppsRoleMatchList,
AppsHTMLPublish,
AppsInit,
AppsReleaseCreate,
AppsReleaseList,
AppsReleaseGet,
AppsEnvPull,
withExtraTips(AppsLogList, "Tip: logs are online-only; keep --environment omitted or set --environment online."),
withExtraTips(AppsLogGet, "Tip: logs are online-only; keep --environment omitted or set --environment online."),
withExtraTips(AppsTraceList, "Tip: traces are online-only; keep --environment omitted or set --environment online."),
withExtraTips(AppsTraceGet, "Tip: traces are online-only; keep --environment omitted or set --environment online."),
withExtraTips(AppsMetricList, "Tip: metrics are online-only; keep --environment omitted or set --environment online."),
withExtraTips(AppsAnalyticsList, "Tip: analytics are online-only; keep --environment omitted or set --environment online."),
AppsEnvVarList,
envSet,
envDelete,
AppsDBTableList,
AppsDBTableGet,
AppsDBExecute,
AppsDBEnvCreate,
AppsDBDataImport,
AppsDBDataExport,
AppsDBChangelogList,
AppsDBAuditStatus,
AppsDBAuditEnable,
AppsDBAuditDisable,
AppsDBAuditList,
AppsDBEnvDiff,
AppsDBEnvMigrate,
AppsDBRecoveryDiff,
AppsDBRecoveryApply,
AppsDBQuotaGet,
AppsFileList,
AppsFileGet,
AppsFileSign,
AppsFileDownload,
AppsFileUpload,
AppsFileDelete,
AppsFileQuotaGet,
AppsCacheGet,
AppsCacheDelete,
AppsCacheClear,
AppsGitCredentialInit,
AppsGitCredentialList,
AppsGitCredentialRemove,
AppsSessionCreate,
AppsSessionList,
AppsSessionGet,
AppsSessionStop,
AppsSessionMessagesList,
AppsChat,
AppsPluginInstall,
AppsPluginUninstall,
AppsPluginList,
// open API key management
AppsOpenAPIKeyList,
AppsOpenAPIKeyGet,
AppsOpenAPIKeyCreate,
AppsOpenAPIKeyUpdate,
AppsOpenAPIKeyEnable,
AppsOpenAPIKeyDisable,
AppsOpenAPIKeyDelete,
AppsOpenAPIKeyReset,
// automation triggers (cron / record-change / webhook / feishu-approval)
AppsAutomationList,
AppsAutomationGet,
AppsAutomationCreate,
AppsAutomationUpdate,
AppsAutomationEnable,
AppsAutomationDisable,
}
}
func withExtraTips(sc common.Shortcut, tips ...string) common.Shortcut {
sc.Tips = append(append([]string{}, sc.Tips...), tips...)
return sc
}