feat(cli): generate Calendar event commands with chrono natural language time#6
Merged
Conversation
…ct view
- New 'raw' shape bypasses JSON/TTY logic and writes data verbatim so
payloads like .ics text survive redirection without JSON quoting. It
intentionally wins over --json/WSPC_OUTPUT because the upstream body is
already the user-facing artifact.
- renderObject now emits non-scalar array fields as an indented sub-list
beneath the scalar rows, recognising the common {email, display_name}
attendee shape and capping output at 10 items with an overflow line.
- event ics passes display.shape='raw' so '> file.ics' writes valid iCalendar text instead of a JSON-escaped string. - event rm passes display.shape='object' with id-short + relative-time formatters for deleted_at.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
新增 Calendar Events 相關的六個 CLI 指令(
add/ls/set/show/rm/ics),藉由擴充tools/cli-codegen/emit.ts讓 OpenAPIx-cli註記可以宣告式驅動 chrono 自然語言時間解析、多重--attendeeflag、API 欄位改名、ICS raw 下載等行為。配合的主 repo PR
https://github.com/sadcoderlabs/wspc/pull/361 — 這個 PR 提供了新的
x-cli註記與 spec sync 來源,需要先合進去。變更分層
f2fe1e3):加chrono-node@2.9.1/luxon@3.7.2,新建src/handwritten/utils/parse-time.ts/parse-date.ts/parse-attendee.ts,含完整單元測試。parseTimeInput對 naive ISO(2026-05-12T10:00沒 offset)會走 chrono 路徑套用--tz,不會悄悄掉到 system zone。7e7abb2):emit.ts加入XCliOption型別與五種屬性(parser/array/mapsTo/allDayFlag/exclusive)。生成的 action body 自動注入resolveTimezone(opts.tz)、parseTimeInput(...).toISO()、parseAttendee等邏輯;只在實際使用時 import 工具。event_ics_download特判把id轉成filename: \${id}.ics。allDayFlag在 body / query 已有同名欄位時不重複 emit。新增 7 個 codegen 單元測試覆蓋每條新分支。de19040):確認src/cli.ts自動註冊event群組;新增test/generated/event.test.ts5 個整合測試,用vi.mock攔 SDK 並斷言請求 shape;以vi.useFakeTimers()+process.env.WSPC_TZ鎖確定性。每個 test 用vi.resetModules()重 import 拿全新 Commander 實例,避免 array accumulator default 跨測試洩漏。1846f69):XCliDisplay.shape新增\"raw\",渲染時跳過 TTY / JSON 判斷直接process.stdout.write— 讓wspc event ics evt_xxx > meeting.ics寫出真實 ICS 而非 JSON-escaped 字串。renderObject補上 array 欄位處理,把attendees渲染成 `N items` + 編號 sub-list(`Alice alice@example.com` / `bob@example.com` 格式)。1e753d6):同步主 repo 的openapi.json並重跑npm run generate,讓ics.ts帶display: { shape: \"raw\" }、rm.ts帶deleted_at: relative-timeformatter。端對端驗證(以真實 production 帳號)
```
wspc event add 'Final UX check' --start 'tomorrow 10am' --end 'tomorrow 11am' --tz 'Asia/Taipei'
--attendee 'Alice alice@example.com' --attendee 'bob@example.com' --location 'Zoom'
wspc event ls --from today --to 'next week' --tz 'Asia/Taipei'
wspc event ics evt_xxx > meeting.ics
wspc event rm evt_xxx
```
確認:`tomorrow 10am` 解析成 `2026-05-28T10:00:00.000+08:00`、`Alice a@x` 拆成 `{email, display_name}`、`--from`/`--to` 送出去變成 `start_from`/`start_to`、redirect 寫的 `.ics` 檔可被 Calendar app 解析、`event rm` 顯示 `deleted_at: just now`。
測試
設計上一個 opinionated 決定
`raw` shape 壓過 `--json`:即使使用者下 `wspc event ics evt_xxx --json` 也吐 raw ICS。理由:把 ICS body 包進 JSON 等於對 `\r\n` 再 escape 一次,沒有 jq / AI consumer 想要這樣。Code comment 跟 commit message 都有記。