Skip to content

feat(sheets): add dropdown shortcuts and formula reference docs#461

Open
caojie0621 wants to merge 1 commit intomainfrom
feat/sheet_skill
Open

feat(sheets): add dropdown shortcuts and formula reference docs#461
caojie0621 wants to merge 1 commit intomainfrom
feat/sheet_skill

Conversation

@caojie0621
Copy link
Copy Markdown
Collaborator

@caojie0621 caojie0621 commented Apr 14, 2026

Summary

The multipleValue cell type silently becomes plain text when the target range
has no dropdown configuration, and the prerequisite data-validation API was not
exposed as a CLI shortcut. This PR adds four new shortcuts wrapping the v2
dataValidation endpoints and documents Lark-specific formula writing rules.

Changes

  • Add +set-dropdown, +update-dropdown, +get-dropdown, +delete-dropdown
    shortcuts in shortcuts/sheets/sheet_dropdown.go
  • Register shortcuts in shortcuts/sheets/shortcuts.go
  • Add 22 unit tests in shortcuts/sheets/sheet_dropdown_test.go
  • Add 4 reference docs (lark-sheets-{set,update,get,delete}-dropdown.md)
  • Add lark-sheets-formula.md reference for ARRAYFORMULA, native array
    functions, MAP/LAMBDA, date diff, and unsupported Excel syntax
  • Update SKILL.md: add dropdown shortcut table, link formula reference,
    clarify multipleValue prerequisite
  • Sync skill-template/domains/sheets.md with latest changes

Test Plan

  • go build and go vet pass
  • 22 unit tests pass (go test ./shortcuts/sheets/ -run Dropdown)
  • All existing sheets tests pass (no regression)
  • E2E verification against live spreadsheet:
    • +set-dropdown with --multiple --highlight --colors
    • +write with multipleValue → read back confirms dropdown values
    • +get-dropdown returns correct config
    • +update-dropdown changes options from 高/中/低 to P0-P3
    • +delete-dropdown removes config, +get-dropdown confirms empty
  • 13 boundary scenarios verified (missing flags, invalid JSON, empty array,
    comma in value, colors mismatch, dry-run, no-dropdown range, etc.)

Related Issues

N/A

Summary by CodeRabbit

  • New Features

    • Added four Sheets dropdown commands: +set-dropdown, +update-dropdown, +get-dropdown, +delete-dropdown — create, modify, query, and remove dropdowns with support for multi-select, validation highlighting, and per-option color mapping.
  • Documentation

    • Added a comprehensive Feishu Sheets formula syntax reference.
    • Added/updated dropdown operation docs and guidance for configuring dropdowns before writing multiple-value data.

@github-actions github-actions bot added domain/ccm PR touches the ccm domain size/L Large or sensitive change across domains or core paths labels Apr 14, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

📝 Walkthrough

Walkthrough

Adds four new Lark Sheets dropdown shortcuts—+set-dropdown, +update-dropdown, +get-dropdown, and +delete-dropdown—with Go implementations, validation/dry-run/execute flows, comprehensive tests, and accompanying reference documentation for usage and formula guidance.

Changes

Cohort / File(s) Summary
Dropdown Shortcut Implementation
shortcuts/sheets/sheet_dropdown.go
New file implementing four exported shortcuts. Centralizes spreadsheet token extraction, JSON-array flag parsing and validation, DataValidation request body construction, and REST path building. Each shortcut implements Validate, DryRun, and Execute with appropriate HTTP methods (POST/PUT/GET/DELETE).
Dropdown Shortcut Tests
shortcuts/sheets/sheet_dropdown_test.go
New test suite covering validation errors (missing creds, malformed JSON, type checks, colors length), dry-run payload assertions, execution HTTP wiring via httpmock, and API error/output handling for all four shortcuts.
Shortcut Registration
shortcuts/sheets/shortcuts.go
Appends SheetSetDropdown, SheetUpdateDropdown, SheetGetDropdown, and SheetDeleteDropdown to the Shortcuts() return slice.
Skill / Domain Docs
skill-template/domains/sheets.md, skills/lark-sheets/SKILL.md
Updates docs: adds formula reference pointer, revises IMPORTRANGE and dropdown guidance, and documents the new "下拉列表" shortcuts.
Reference Documentation
skills/lark-sheets/references/lark-sheets-set-dropdown.md, ...-update-dropdown.md, ...-get-dropdown.md, ...-delete-dropdown.md, ...-formula.md
Adds five new reference pages detailing usage, flags, examples, outputs, and Feishu-specific formula rules and examples.

Sequence Diagram

sequenceDiagram
    participant User as CLI User
    participant CLI as lark-cli sheets<br/>(+set/update/get/delete-dropdown)
    participant Runtime as runtime.CallAPI
    participant API as Sheets API

    User->>CLI: Invoke shortcut with flags (--url/--spreadsheet-token, ranges, condition-values, ...)
    CLI->>CLI: Validate flags & parse JSON arrays
    CLI->>CLI: If --dry-run: construct HTTP request payload
    CLI->>Runtime: CallAPI(method, path, body/query)
    Runtime->>API: HTTP request to Sheets API (POST/PUT/GET/DELETE)
    API-->>Runtime: HTTP response (200 or error)
    Runtime-->>CLI: Response payload or error
    CLI-->>User: Print JSON result or error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • fangshuyu-768
  • zhouyue-bytedance

Poem

🐰 Hop hop, the dropdowns bloom anew,
Options set, updated, fetched, and cleft—phew!
Tests hop in lines to prove each route,
Docs sing formulas and how to sprout.
Little rabbit cheers: click, run, and tout!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.15% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: adding dropdown shortcuts and formula reference documentation to the sheets package.
Description check ✅ Passed The description covers all required template sections: Summary explains the motivation, Changes lists main modifications, Test Plan documents verification steps, and Related Issues is addressed.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/sheet_skill

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 14, 2026

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@c877f7206ebef63887b54415b40b45b0b543fb8c

🧩 Skill update

npx skills add larksuite/cli#feat/sheet_skill -y -g

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 14, 2026

Greptile Summary

This PR adds four dropdown-management shortcuts (+set-dropdown, +update-dropdown, +get-dropdown, +delete-dropdown) wrapping the Lark Sheets v2 dataValidation endpoints, 22 unit tests, and reference documentation including a new formula-syntax guide and corrections to the IMPORTRANGE limit and multipleValue prerequisite descriptions. The implementation is consistent with the existing shortcut patterns in the codebase and the previous-thread concerns (nil dvRanges, colors validation in Validate) appear to be addressed.

Confidence Score: 5/5

  • Safe to merge; all remaining findings are P2 style and UX suggestions that do not affect correctness.
  • No P0/P1 issues found. The three P2 findings are: a misleading error message when URL extraction fails alongside a valid --spreadsheet-token, missing empty-array guard in parseJSONStringArray, and a minor doc–code inconsistency on --colors required-with-highlight. None of these cause incorrect data to be sent to the API or cause runtime failures.
  • shortcuts/sheets/sheet_dropdown.go — validateDropdownToken URL-override logic and empty-array validation

Important Files Changed

Filename Overview
shortcuts/sheets/sheet_dropdown.go New file implementing four dropdown shortcuts; core logic is clean and consistent with codebase patterns, but validateDropdownToken silently discards a valid --spreadsheet-token when --url is provided but fails to parse, and parseJSONStringArray does not reject an empty array for condition-values.
shortcuts/sheets/sheet_dropdown_test.go 22 unit tests covering validate/dry-run/execute paths; TestSetDropdownExecuteWithMultipleAndColors checks multipleValues and highlightValidData but does not assert the colors array in the captured request body, leaving that branch untested.
shortcuts/sheets/shortcuts.go Registers the four new dropdown shortcuts; straightforward append, no issues.
skills/lark-sheets/references/lark-sheets-set-dropdown.md Comprehensive reference doc; the parameter table labels --colors as "必填" when --highlight is true, but the implementation does not enforce this, creating a doc–code inconsistency.
skills/lark-sheets/references/lark-sheets-formula.md New formula reference doc; content is accurate and well-structured.
skills/lark-sheets/SKILL.md Adds dropdown section and formula reference link; the IMPORTRANGE correction (from "not supported" to "up to 5 levels deep") is a meaningful accuracy improvement.
skill-template/domains/sheets.md Mirrors the SKILL.md changes for the template; consistent and correct.
skills/lark-sheets/references/lark-sheets-delete-dropdown.md New reference doc for +delete-dropdown; well-structured with correct output schema.
skills/lark-sheets/references/lark-sheets-get-dropdown.md New reference doc for +get-dropdown; output fields match the Lark v2 API response structure.
skills/lark-sheets/references/lark-sheets-update-dropdown.md New reference doc for +update-dropdown; parameters and output description are consistent with the implementation.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A([User invokes shortcut]) --> B{flag --url set?}
    B -- yes --> C[extractSpreadsheetToken]
    C --> D{token empty?}
    D -- yes --> E[error: specify --url or --spreadsheet-token]
    D -- no --> F[token ok]
    B -- no --> G{--spreadsheet-token set?}
    G -- yes --> F
    G -- no --> E

    F --> H[Validate]
    H --> H1[validateDropdownToken]
    H --> H2[parseJSONStringArray condition-values]
    H2 --> H3{empty array?}
    H3 -- yes --> ERR[local validation error]
    H3 -- no --> H4[buildDropdownBody]
    H4 --> H5[parse colors if provided]
    H5 --> H6{length mismatch?}
    H6 -- yes --> ERR
    H6 -- no --> OK

    OK --> I{--dry-run?}
    I -- yes --> J[DryRun: print JSON preview]
    I -- no --> K[Execute: CallAPI]
    K --> L{HTTP error?}
    L -- yes --> M[return error]
    L -- no --> N[runtime.Out result]
Loading

Reviews (2): Last reviewed commit: "feat(sheets): add dropdown shortcuts and..." | Re-trigger Greptile

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 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_dropdown.go`:
- Around line 60-66: Call the same validation used in buildDropdownBody for the
--colors flag inside SheetUpdateDropdown.Validate (after parsing --ranges) and
likewise in the other Validate blocks/dry-run builders so malformed JSON is
rejected early; specifically, invoke parseJSONStringArray("colors",
runtime.Str("colors")) (or the helper used by buildDropdownBody) and return its
error if present, and also enforce that the parsed colors slice length matches
the --condition-values slice length (1:1 palette) before proceeding so dry-run
and Validate both fail on bad or mismatched --colors.
- Around line 35-40: parseJSONStringArray currently unmarshals into
[]interface{}, which accepts null and mixed-type arrays; update
parseJSONStringArray to enforce a string-array contract by unmarshaling into
[]string (or unmarshaling into []interface{} then validating each element is a
non-nil string) and return a FlagErrorf if the result is nil (null input) or any
element is not a string; keep the same function signature and use flagName in
the error messages to indicate which flag failed validation.

In `@skills/lark-sheets/references/lark-sheets-formula.md`:
- Around line 31-34: Update the SKILL.md statement that claims IMPORTRANGE is
unsupported: find the sentence in skills/lark-sheets/SKILL.md (around the
section describing formula limitations) that blocks cross-sheet references and
change it to state that IMPORTRANGE is supported, including the correct
constraints (supported syntax, up to 5 nesting levels and ~100 references per
sheet) and remove the prohibition. Ensure any example or note referencing lack
of cross-sheet support is replaced with a brief supported-example mention and
the documented limits, and update or remove related tests/comments that assert
IMPORTRANGE is unavailable.
🪄 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: 39e3fe00-c177-4918-b072-b32b4ea2fc8c

📥 Commits

Reviewing files that changed from the base of the PR and between 2a30124 and abe810e.

📒 Files selected for processing (10)
  • shortcuts/sheets/sheet_dropdown.go
  • shortcuts/sheets/sheet_dropdown_test.go
  • shortcuts/sheets/shortcuts.go
  • skill-template/domains/sheets.md
  • skills/lark-sheets/SKILL.md
  • skills/lark-sheets/references/lark-sheets-delete-dropdown.md
  • skills/lark-sheets/references/lark-sheets-formula.md
  • skills/lark-sheets/references/lark-sheets-get-dropdown.md
  • skills/lark-sheets/references/lark-sheets-set-dropdown.md
  • skills/lark-sheets/references/lark-sheets-update-dropdown.md

Implement +set-dropdown, +update-dropdown, +get-dropdown, and
+delete-dropdown shortcuts wrapping the v2 dataValidation API.
This resolves the issue where multipleValue writes silently
became plain text because the prerequisite dropdown configuration
step was not exposed as a CLI command.

Also add lark-sheets-formula.md reference for Lark-specific formula
rules (ARRAYFORMULA, native array functions, date diff, etc.) and
update the dropdown limitation note in SKILL.md to link to the new
+set-dropdown shortcut.
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
shortcuts/sheets/sheet_dropdown_test.go (1)

6-15: Remove the bytes sentinel; it’s dead code in this test file.

Line 466-Line 467 only exist to justify an otherwise unnecessary import. Dropping both improves readability without behavior change.

Proposed cleanup
 import (
-	"bytes"
 	"context"
 	"encoding/json"
 	"strings"
 	"testing"

 	"github.com/larksuite/cli/internal/cmdutil"
 	"github.com/larksuite/cli/internal/httpmock"
 )
@@
-// suppress unused import for bytes in case the test helpers already import it
-var _ = (*bytes.Buffer)(nil)

Also applies to: 466-467

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shortcuts/sheets/sheet_dropdown_test.go` around lines 6 - 15, Remove the
unused bytes import and its sentinel usage: delete the import "bytes" from the
import block and remove the two sentinel lines that reference bytes (the lines
added to justify the import, e.g., any var/_ or dummy usage like bytes.NewBuffer
or similar). Update imports (go fmt/gofmt will reorder) and run tests to ensure
no other references to the bytes symbol remain.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@shortcuts/sheets/sheet_dropdown_test.go`:
- Around line 6-15: Remove the unused bytes import and its sentinel usage:
delete the import "bytes" from the import block and remove the two sentinel
lines that reference bytes (the lines added to justify the import, e.g., any
var/_ or dummy usage like bytes.NewBuffer or similar). Update imports (go
fmt/gofmt will reorder) and run tests to ensure no other references to the bytes
symbol remain.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e9e8bfd4-9c91-4e8f-bacd-4c133acc8e63

📥 Commits

Reviewing files that changed from the base of the PR and between abe810e and c877f72.

📒 Files selected for processing (10)
  • shortcuts/sheets/sheet_dropdown.go
  • shortcuts/sheets/sheet_dropdown_test.go
  • shortcuts/sheets/shortcuts.go
  • skill-template/domains/sheets.md
  • skills/lark-sheets/SKILL.md
  • skills/lark-sheets/references/lark-sheets-delete-dropdown.md
  • skills/lark-sheets/references/lark-sheets-formula.md
  • skills/lark-sheets/references/lark-sheets-get-dropdown.md
  • skills/lark-sheets/references/lark-sheets-set-dropdown.md
  • skills/lark-sheets/references/lark-sheets-update-dropdown.md
✅ Files skipped from review due to trivial changes (7)
  • skills/lark-sheets/references/lark-sheets-set-dropdown.md
  • skills/lark-sheets/references/lark-sheets-delete-dropdown.md
  • skills/lark-sheets/references/lark-sheets-get-dropdown.md
  • shortcuts/sheets/shortcuts.go
  • skills/lark-sheets/references/lark-sheets-update-dropdown.md
  • skills/lark-sheets/references/lark-sheets-formula.md
  • shortcuts/sheets/sheet_dropdown.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • skill-template/domains/sheets.md
  • skills/lark-sheets/SKILL.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain/ccm PR touches the ccm domain size/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant