feat(sheets): add filter view and condition shortcuts#422
Conversation
📝 WalkthroughWalkthroughAdds 10 new Sheets CLI shortcuts (5 for filter views, 5 for filter-view conditions), their implementations and helpers, token validation, comprehensive tests, registers the shortcuts, and adds corresponding documentation pages. Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as CLI (lark-cli)
participant Runtime as RuntimeContext
participant API as Sheets API (v3)
participant Out as stdout
CLI->>Runtime: Validate flags, derive token (--url or --spreadsheet-token)
CLI->>Runtime: Build path & body (path helpers, buildConditionBody)
Runtime->>API: CallAPI(method, path, body, token)
API-->>Runtime: HTTP response (200/4xx/5xx)
Runtime-->>Out: write response JSON or error
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
0f2dce2 to
19324bf
Compare
Greptile SummaryThis PR adds 10 new Confidence Score: 5/5Safe to merge; the only remaining finding is a minor edge-case P2 that requires deliberately passing an empty-string flag value. Both previously-flagged P1 issues (no-op update validators) are resolved. The remaining P2 concern — a semantic gap between Changed-flag validation and empty-string body-building in buildConditionBody — requires an adversarial empty-string argument to trigger and is unlikely in normal use. All 39 tests pass, DryRun/Execute paths are consistent, and path-segment encoding is applied throughout. shortcuts/sheets/sheet_filter_view_condition.go — the buildConditionBody/Validate gap described in the inline comment. Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant CLI
participant LarkAPI
User->>CLI: sheets +create-filter-view --range ...
CLI->>LarkAPI: POST /spreadsheets/:token/sheets/:sheetId/filter_views
LarkAPI-->>CLI: { filter_view: { filter_view_id, range } }
CLI-->>User: JSON output
User->>CLI: sheets +create-filter-view-condition --filter-type number ...
CLI->>LarkAPI: POST .../filter_views/:fvId/conditions
LarkAPI-->>CLI: { condition: { condition_id, filter_type, ... } }
CLI-->>User: JSON output
User->>CLI: sheets +update-filter-view-condition --filter-type text ...
CLI->>LarkAPI: PUT .../filter_views/:fvId/conditions/:condId
LarkAPI-->>CLI: { condition: { ... } }
CLI-->>User: JSON output
User->>CLI: sheets +delete-filter-view
CLI->>LarkAPI: DELETE .../filter_views/:fvId
LarkAPI-->>CLI: { code: 0 }
CLI-->>User: JSON output
Reviews (2): Last reviewed commit: "feat(sheets): add filter view and condit..." | Re-trigger Greptile |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@shortcuts/sheets/sheet_filter_view_condition.go`:
- Around line 80-103: The Validate implementation in the
sheet_filter_view_condition.go command only checks auth token and allows no-op
updates; change Validate (the Validate func) to also require at least one of the
update flags before returning success: inspect runtime.Str or
runtime.Has/appropriate accessors for "filter-type", "compare-type", and
"expected" (the same keys used by buildConditionBody) and if all three are
empty/absent return a descriptive error (e.g., "must provide at least one of
--filter-type, --compare-type, or --expected"); keep the existing token
validation by calling validateFilterViewToken(runtime) first and return its
error if present.
In `@shortcuts/sheets/sheet_filter_view.go`:
- Around line 99-125: The current Validate in the +update-filter-view shortcut
only checks token and allows an empty PATCH body; update the Validate function
(the Validate closure that calls validateFilterViewToken) to also require that
at least one of runtime.Str("range") or runtime.Str("filter-view-name") is
non-empty and return a clear error if both are empty so users get an immediate
CLI error; keep the DryRun and Execute body-building logic (which reads
runtime.Str("range") and runtime.Str("filter-view-name")) unchanged so the
validation matches what filterViewItemPath/runtime.CallAPI expect.
In `@skills/lark-sheets/references/lark-sheets-get-filter-view.md`:
- Around line 19-22: Update the documentation for the lark-sheets Get Filter
View flags to indicate that the `--url` and `--spreadsheet-token` flags are
mutually optional but one is required: clarify in the table row for `--url` and
`--spreadsheet-token` (and/or add a short note below the table) that at least
one of `--url` or `--spreadsheet-token` must be provided to avoid the flag
validation error when both are omitted.
In `@skills/lark-sheets/references/lark-sheets-list-filter-view-conditions.md`:
- Around line 21-24: The doc incorrectly marks both `--url` and
`--spreadsheet-token` as optional for the `+list-filter-view-conditions`
command; update the wording and table so it clearly states that one of these two
auth inputs is mandatory (i.e., "one of `--url` or `--spreadsheet-token` must be
provided"), and adjust the description for `--url` and `--spreadsheet-token` in
the table to indicate "one required" or add a note that the command rejects
requests when both are omitted; reference the `+list-filter-view-conditions`
command and the `--url`/`--spreadsheet-token` flags when making this change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 41e4ea8f-0bea-4b3e-a7fe-fe5dad00c480
📒 Files selected for processing (15)
shortcuts/sheets/sheet_filter_view.goshortcuts/sheets/sheet_filter_view_condition.goshortcuts/sheets/sheet_filter_view_test.goshortcuts/sheets/shortcuts.goskills/lark-sheets/SKILL.mdskills/lark-sheets/references/lark-sheets-create-filter-view-condition.mdskills/lark-sheets/references/lark-sheets-create-filter-view.mdskills/lark-sheets/references/lark-sheets-delete-filter-view-condition.mdskills/lark-sheets/references/lark-sheets-delete-filter-view.mdskills/lark-sheets/references/lark-sheets-get-filter-view-condition.mdskills/lark-sheets/references/lark-sheets-get-filter-view.mdskills/lark-sheets/references/lark-sheets-list-filter-view-conditions.mdskills/lark-sheets/references/lark-sheets-list-filter-views.mdskills/lark-sheets/references/lark-sheets-update-filter-view-condition.mdskills/lark-sheets/references/lark-sheets-update-filter-view.md
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@32f08695331c9ca943d9eb0c02838e2badb71323🧩 Skill updatenpx skills add larksuite/cli#feat/filter_view -y -g |
There was a problem hiding this comment.
♻️ Duplicate comments (2)
shortcuts/sheets/sheet_filter_view_condition.go (1)
80-83:⚠️ Potential issue | 🟡 MinorReject empty
+update-filter-view-conditionupdates inValidate.This path currently allows
PUT {}when none of--filter-type,--compare-type, or--expectedis provided. Please validate this upfront.Suggested fix
Validate: func(ctx context.Context, runtime *common.RuntimeContext) error { - _, err := validateFilterViewToken(runtime) - return err + if _, err := validateFilterViewToken(runtime); err != nil { + return err + } + if runtime.Str("filter-type") == "" && + runtime.Str("compare-type") == "" && + runtime.Str("expected") == "" { + return common.FlagErrorf("specify at least one of --filter-type, --compare-type, or --expected") + } + return nil },Also applies to: 84-97
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@shortcuts/sheets/sheet_filter_view_condition.go` around lines 80 - 83, The Validate function in sheet_filter_view_condition.go currently returns success for empty update payloads; update it to explicitly reject requests that don't provide any of the updatable fields by checking the runtime for at least one of the flags/values (--filter-type, --compare-type, --expected) before calling validateFilterViewToken, and return an error if none are present; apply the same check for the other Validate blocks around the 84-97 region so both update paths enforce "no-empty-update" validation using the same flag presence logic and error message.shortcuts/sheets/sheet_filter_view.go (1)
99-102:⚠️ Potential issue | 🟡 MinorReject no-op
+update-filter-viewrequests in validation.
+update-filter-viewcurrently allowsPATCH {}when neither--rangenor--filter-view-nameis set. Please fail fast inValidatewith a flag error.Suggested fix
Validate: func(ctx context.Context, runtime *common.RuntimeContext) error { - _, err := validateFilterViewToken(runtime) - return err + if _, err := validateFilterViewToken(runtime); err != nil { + return err + } + if runtime.Str("range") == "" && runtime.Str("filter-view-name") == "" { + return common.FlagErrorf("specify --range or --filter-view-name") + } + return nil },Also applies to: 103-115, 116-126
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@shortcuts/sheets/sheet_filter_view.go` around lines 99 - 102, The Validate implementation for the +update-filter-view command currently only calls validateFilterViewToken(runtime) and permits no-op PATCH requests; update Validate (the anonymous Validate func and the related validators around validateFilterViewToken) to check that at least one of the change flags is present (e.g., runtime.Flags or the parsed flags for --range and --filter-view-name) and return a flag error when both are empty, so the command fails fast instead of allowing PATCH {}. Locate the anonymous Validate function(s) that call validateFilterViewToken and add a pre-check that inspects the runtime/flags for --range or --filter-view-name, returning a descriptive flag error if neither is provided. Ensure the same change is applied to the other similar Validate blocks referenced (lines handling the same command).
🧹 Nitpick comments (1)
shortcuts/sheets/sheet_filter_view.go (1)
53-75: Extract duplicated filter-view body construction to one helper.Create/update each build the same body twice (DryRun + Execute). A shared helper will reduce drift risk.
Also applies to: 103-125
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@shortcuts/sheets/sheet_filter_view.go` around lines 53 - 75, Both DryRun and Execute duplicate the same body construction (using runtime.Str("range"), "filter-view-name", "filter-view-id"); create a small helper function (e.g., buildFilterViewBody(runtime *common.RuntimeContext) map[string]interface{}) and replace the inline body creation in DryRun and Execute with a call to that helper, keeping validateFilterViewToken and filterViewBasePath usage unchanged; also update the other similar block (lines ~103-125) to use the same helper so both cases share one source of truth.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@shortcuts/sheets/sheet_filter_view_condition.go`:
- Around line 80-83: The Validate function in sheet_filter_view_condition.go
currently returns success for empty update payloads; update it to explicitly
reject requests that don't provide any of the updatable fields by checking the
runtime for at least one of the flags/values (--filter-type, --compare-type,
--expected) before calling validateFilterViewToken, and return an error if none
are present; apply the same check for the other Validate blocks around the 84-97
region so both update paths enforce "no-empty-update" validation using the same
flag presence logic and error message.
In `@shortcuts/sheets/sheet_filter_view.go`:
- Around line 99-102: The Validate implementation for the +update-filter-view
command currently only calls validateFilterViewToken(runtime) and permits no-op
PATCH requests; update Validate (the anonymous Validate func and the related
validators around validateFilterViewToken) to check that at least one of the
change flags is present (e.g., runtime.Flags or the parsed flags for --range and
--filter-view-name) and return a flag error when both are empty, so the command
fails fast instead of allowing PATCH {}. Locate the anonymous Validate
function(s) that call validateFilterViewToken and add a pre-check that inspects
the runtime/flags for --range or --filter-view-name, returning a descriptive
flag error if neither is provided. Ensure the same change is applied to the
other similar Validate blocks referenced (lines handling the same command).
---
Nitpick comments:
In `@shortcuts/sheets/sheet_filter_view.go`:
- Around line 53-75: Both DryRun and Execute duplicate the same body
construction (using runtime.Str("range"), "filter-view-name", "filter-view-id");
create a small helper function (e.g., buildFilterViewBody(runtime
*common.RuntimeContext) map[string]interface{}) and replace the inline body
creation in DryRun and Execute with a call to that helper, keeping
validateFilterViewToken and filterViewBasePath usage unchanged; also update the
other similar block (lines ~103-125) to use the same helper so both cases share
one source of truth.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1e9c1b69-74f4-444c-b260-8477bf035145
📒 Files selected for processing (15)
shortcuts/sheets/sheet_filter_view.goshortcuts/sheets/sheet_filter_view_condition.goshortcuts/sheets/sheet_filter_view_test.goshortcuts/sheets/shortcuts.goskills/lark-sheets/SKILL.mdskills/lark-sheets/references/lark-sheets-create-filter-view-condition.mdskills/lark-sheets/references/lark-sheets-create-filter-view.mdskills/lark-sheets/references/lark-sheets-delete-filter-view-condition.mdskills/lark-sheets/references/lark-sheets-delete-filter-view.mdskills/lark-sheets/references/lark-sheets-get-filter-view-condition.mdskills/lark-sheets/references/lark-sheets-get-filter-view.mdskills/lark-sheets/references/lark-sheets-list-filter-view-conditions.mdskills/lark-sheets/references/lark-sheets-list-filter-views.mdskills/lark-sheets/references/lark-sheets-update-filter-view-condition.mdskills/lark-sheets/references/lark-sheets-update-filter-view.md
✅ Files skipped from review due to trivial changes (10)
- skills/lark-sheets/references/lark-sheets-list-filter-view-conditions.md
- skills/lark-sheets/references/lark-sheets-get-filter-view.md
- skills/lark-sheets/references/lark-sheets-get-filter-view-condition.md
- skills/lark-sheets/references/lark-sheets-list-filter-views.md
- skills/lark-sheets/references/lark-sheets-delete-filter-view-condition.md
- skills/lark-sheets/references/lark-sheets-update-filter-view.md
- skills/lark-sheets/references/lark-sheets-create-filter-view-condition.md
- skills/lark-sheets/references/lark-sheets-create-filter-view.md
- skills/lark-sheets/references/lark-sheets-delete-filter-view.md
- skills/lark-sheets/references/lark-sheets-update-filter-view-condition.md
🚧 Files skipped from review as they are similar to previous changes (3)
- shortcuts/sheets/shortcuts.go
- skills/lark-sheets/SKILL.md
- shortcuts/sheets/sheet_filter_view_test.go
Add 10 new sheet shortcuts for filter view management: Filter views: - +create-filter-view, +update-filter-view, +list-filter-views - +get-filter-view, +delete-filter-view Filter view conditions: - +create-filter-view-condition, +update-filter-view-condition - +list-filter-view-conditions, +get-filter-view-condition - +delete-filter-view-condition Includes unit tests (39 cases, 88-93% coverage) and skill reference docs.
19324bf to
32f0869
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (2)
shortcuts/sheets/sheet_filter_view.go (1)
103-106:⚠️ Potential issue | 🟡 Minor
+update-filter-viewstill allows a no-op with empty values.Line 103 checks only whether flags were set, not whether they carry usable values.
--range ""and--filter-view-name ""can pass validation and still produce an empty PATCH body downstream.Suggested fix
Validate: func(ctx context.Context, runtime *common.RuntimeContext) error { if _, err := validateFilterViewToken(runtime); err != nil { return err } - if !runtime.Cmd.Flags().Changed("range") && - !runtime.Cmd.Flags().Changed("filter-view-name") { - return common.FlagErrorf("specify at least one of --range or --filter-view-name") + if runtime.Str("range") == "" && runtime.Str("filter-view-name") == "" { + return common.FlagErrorf("specify at least one of --range or --filter-view-name with a non-empty value") } return nil },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@shortcuts/sheets/sheet_filter_view.go` around lines 103 - 106, The current validation only checks whether flags were set (runtime.Cmd.Flags().Changed) and thus allows empty values like --range "" or --filter-view-name ""; update the check to read the actual flag values (e.g., runtime.Cmd.Flags().GetString("range") and GetString("filter-view-name")), trim them and ensure at least one is non-empty, and if both are empty return the same common.FlagErrorf("specify at least one of --range or --filter-view-name"); this prevents creating an empty PATCH body downstream in the update-filter-view handler.shortcuts/sheets/sheet_filter_view_condition.go (1)
86-93:⚠️ Potential issue | 🟡 Minor
+update-filter-view-conditioncan still pass with no effective update.Line 86 only checks whether flags changed. If users pass empty values (for example
--expected ""), validation can pass but the request body remains empty because Line 254 only includes non-empty values.Suggested fix
Validate: func(ctx context.Context, runtime *common.RuntimeContext) error { if _, err := validateFilterViewToken(runtime); err != nil { return err } - if !runtime.Cmd.Flags().Changed("filter-type") && - !runtime.Cmd.Flags().Changed("compare-type") && - !runtime.Cmd.Flags().Changed("expected") { - return common.FlagErrorf("specify at least one of --filter-type, --compare-type, or --expected") + if runtime.Str("filter-type") == "" && + runtime.Str("compare-type") == "" && + runtime.Str("expected") == "" { + return common.FlagErrorf("specify at least one of --filter-type, --compare-type, or --expected with a non-empty value") } if s := runtime.Str("expected"); s != "" { return validateExpectedFlag(s) } return nil },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@shortcuts/sheets/sheet_filter_view_condition.go` around lines 86 - 93, The current guard only checks whether flags were changed (runtime.Cmd.Flags().Changed) which allows empty values (e.g., runtime.Str("expected") == "") to pass but produce no effective update; change the check to require at least one flag that is both changed and has a non-empty value (e.g., check runtime.Cmd.Flags().Changed("expected") && runtime.Str("expected") != ""), or alternatively after constructing the request body (the code path that only includes non-empty values) validate that the body is not empty and return a FlagErrorf if it is; also keep the existing validateExpectedFlag(runtime.Str("expected")) call but only invoke it when runtime.Str("expected") is non-empty.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@shortcuts/sheets/sheet_filter_view_condition.go`:
- Around line 86-93: The current guard only checks whether flags were changed
(runtime.Cmd.Flags().Changed) which allows empty values (e.g.,
runtime.Str("expected") == "") to pass but produce no effective update; change
the check to require at least one flag that is both changed and has a non-empty
value (e.g., check runtime.Cmd.Flags().Changed("expected") &&
runtime.Str("expected") != ""), or alternatively after constructing the request
body (the code path that only includes non-empty values) validate that the body
is not empty and return a FlagErrorf if it is; also keep the existing
validateExpectedFlag(runtime.Str("expected")) call but only invoke it when
runtime.Str("expected") is non-empty.
In `@shortcuts/sheets/sheet_filter_view.go`:
- Around line 103-106: The current validation only checks whether flags were set
(runtime.Cmd.Flags().Changed) and thus allows empty values like --range "" or
--filter-view-name ""; update the check to read the actual flag values (e.g.,
runtime.Cmd.Flags().GetString("range") and GetString("filter-view-name")), trim
them and ensure at least one is non-empty, and if both are empty return the same
common.FlagErrorf("specify at least one of --range or --filter-view-name"); this
prevents creating an empty PATCH body downstream in the update-filter-view
handler.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a663b09c-08d8-44cf-90e4-f3c9f2cb85ee
📒 Files selected for processing (15)
shortcuts/sheets/sheet_filter_view.goshortcuts/sheets/sheet_filter_view_condition.goshortcuts/sheets/sheet_filter_view_test.goshortcuts/sheets/shortcuts.goskills/lark-sheets/SKILL.mdskills/lark-sheets/references/lark-sheets-create-filter-view-condition.mdskills/lark-sheets/references/lark-sheets-create-filter-view.mdskills/lark-sheets/references/lark-sheets-delete-filter-view-condition.mdskills/lark-sheets/references/lark-sheets-delete-filter-view.mdskills/lark-sheets/references/lark-sheets-get-filter-view-condition.mdskills/lark-sheets/references/lark-sheets-get-filter-view.mdskills/lark-sheets/references/lark-sheets-list-filter-view-conditions.mdskills/lark-sheets/references/lark-sheets-list-filter-views.mdskills/lark-sheets/references/lark-sheets-update-filter-view-condition.mdskills/lark-sheets/references/lark-sheets-update-filter-view.md
✅ Files skipped from review due to trivial changes (11)
- skills/lark-sheets/references/lark-sheets-get-filter-view.md
- skills/lark-sheets/references/lark-sheets-delete-filter-view-condition.md
- skills/lark-sheets/references/lark-sheets-list-filter-views.md
- skills/lark-sheets/references/lark-sheets-update-filter-view.md
- skills/lark-sheets/references/lark-sheets-get-filter-view-condition.md
- skills/lark-sheets/references/lark-sheets-update-filter-view-condition.md
- skills/lark-sheets/references/lark-sheets-delete-filter-view.md
- skills/lark-sheets/references/lark-sheets-create-filter-view-condition.md
- shortcuts/sheets/shortcuts.go
- skills/lark-sheets/references/lark-sheets-list-filter-view-conditions.md
- skills/lark-sheets/references/lark-sheets-create-filter-view.md
🚧 Files skipped from review as they are similar to previous changes (2)
- skills/lark-sheets/SKILL.md
- shortcuts/sheets/sheet_filter_view_test.go
Add 10 new sheet shortcuts for filter view management: Filter views: - +create-filter-view, +update-filter-view, +list-filter-views - +get-filter-view, +delete-filter-view Filter view conditions: - +create-filter-view-condition, +update-filter-view-condition - +list-filter-view-conditions, +get-filter-view-condition - +delete-filter-view-condition Includes unit tests (39 cases, 88-93% coverage) and skill reference docs.
Summary
Add 10 new
sheetsshortcuts for filter view and filter condition CRUD, covering the full lifecycle of spreadsheet filter views.Changes
Filter views (5)
+create-filter-view: create a filter view with range, optional name and custom ID+update-filter-view: update filter view range or name+list-filter-views: list all filter views in a sheet+get-filter-view: get a filter view by ID+delete-filter-view: delete a filter viewFilter view conditions (5)
+create-filter-view-condition: create a filter condition on a column (number/text/color/hiddenValue)+update-filter-view-condition: update a filter condition+list-filter-view-conditions: list all conditions of a filter view+get-filter-view-condition: get a condition by column+delete-filter-view-condition: delete a conditionOther
Test Plan
go test ./shortcuts/sheets/)lark-cli sheets +xxxcommands work as expectedRelated Issues
Summary by CodeRabbit
New Features
Documentation
Tests