Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions scripts/fetch_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,24 @@ def main():
parser = argparse.ArgumentParser(description="Fetch meta_data.json for build-time embedding")
parser.add_argument("--brand", default="feishu", choices=["feishu", "lark"],
help="API brand (default: feishu)")
parser.add_argument("--force", action="store_true",
help="force refresh from remote even if local file exists")
args = parser.parse_args()

if os.path.exists(OUT_PATH) and not args.force:
if os.path.isfile(OUT_PATH):
try:
with open(OUT_PATH, "r", encoding="utf-8") as fp:
local = json.load(fp)
if local.get("services"):
print(f"fetch-meta: {OUT_PATH} already exists, skipping (use --force to re-fetch)", file=sys.stderr)
return
print(f"fetch-meta: {OUT_PATH} has no services, re-fetching", file=sys.stderr)
except (OSError, json.JSONDecodeError):
print(f"fetch-meta: {OUT_PATH} is invalid JSON, re-fetching", file=sys.stderr)
else:
print(f"fetch-meta: {OUT_PATH} is not a file, re-fetching", file=sys.stderr)

data = fetch_remote(args.brand)
count = len(data.get("services", []))
print(f"fetch-meta: OK, {count} services from remote API", file=sys.stderr)
Expand Down
40 changes: 40 additions & 0 deletions shortcuts/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
package shortcuts

import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"

"github.com/larksuite/cli/internal/cmdutil"
Expand Down Expand Up @@ -88,3 +92,39 @@ func TestRegisterShortcutsReusesExistingServiceCommand(t *testing.T) {
t.Fatal("base workspace shortcut not mounted on existing service command")
}
}

func TestGenerateShortcutsJSON(t *testing.T) {
output := os.Getenv("SHORTCUTS_OUTPUT")
if output == "" {
t.Skip("set SHORTCUTS_OUTPUT env to generate shortcuts.json")
}

shortcuts := AllShortcuts()

type entry struct {
Verb string `json:"verb"`
Description string `json:"description"`
Scopes []string `json:"scopes"`
}
grouped := make(map[string][]entry)
for _, s := range shortcuts {
verb := strings.TrimPrefix(s.Command, "+")
grouped[s.Service] = append(grouped[s.Service], entry{
Verb: verb,
Description: s.Description,
Scopes: s.ScopesForIdentity("user"),
Comment thread
MaxHuang22 marked this conversation as resolved.
})
}
Comment thread
MaxHuang22 marked this conversation as resolved.

data, err := json.MarshalIndent(grouped, "", " ")
if err != nil {
t.Fatalf("marshal shortcuts: %v", err)
}
if err := os.MkdirAll(filepath.Dir(output), 0o755); err != nil {
t.Fatalf("mkdir: %v", err)
}
if err := os.WriteFile(output, data, 0o644); err != nil {
t.Fatalf("write file: %v", err)
}
t.Logf("wrote %d bytes to %s", len(data), output)
}
Loading