Skip to content

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

Merged
fangshuyu-768 merged 1 commit intomainfrom
feat/sheet_skill
Apr 14, 2026
Merged

feat(sheets): add dropdown shortcuts and formula reference docs#461
fangshuyu-768 merged 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, per-option color mapping, fully-qualified ranges, and a --dry-run preview.
  • Documentation

    • Added a Feishu Sheets formula reference and detailed docs for setting/updating/getting/deleting dropdowns, usage examples, limits, and dry-run/output formats.

@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 (Validate/DryRun/Execute), comprehensive tests, and accompanying reference documentation and SKILL updates.

Changes

Cohort / File(s) Summary
Dropdown Shortcut Implementation
shortcuts/sheets/sheet_dropdown.go
New file adding four exported shortcuts. Implements token extraction (--url/--spreadsheet-token), JSON-array flag parsing/validation, dataValidation request body construction, range validation, and REST path builders. Each shortcut implements Validate, DryRun, and Execute using POST/PUT/GET/DELETE.
Dropdown Shortcut Tests
shortcuts/sheets/sheet_dropdown_test.go
New comprehensive tests covering flag validation (missing creds, malformed JSON, type checks, empty arrays, colors length mismatch, range qualification), dry-run payload assertions, execution wiring with HTTP stubs, request-body inspections, and API error/output handling.
Shortcut Registration
shortcuts/sheets/shortcuts.go
Appends SheetSetDropdown, SheetUpdateDropdown, SheetGetDropdown, and SheetDeleteDropdown to the Shortcuts() returned slice.
Skill / Domain Docs
skill-template/domains/sheets.md, skills/lark-sheets/SKILL.md
Documentation updates: adds formula reference pointer, revises IMPORTRANGE and dropdown guidance, and documents the new dropdown shortcuts in SKILL.md.
Reference Documentation
skills/lark-sheets/references/lark-sheets-set-dropdown.md, ...-update-dropdown.md, ...-get-dropdown.md, ...-delete-dropdown.md, ...-formula.md
Adds five reference pages describing usage, flags, examples, outputs, constraints (range limits, colors mapping), and Feishu-specific formula guidance.

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

Suggested reviewers

  • fangshuyu-768
  • liujinkun2025

Poem

🐰 Hop hop, the dropdowns wake and play,
Set, update, fetch, delete — a busy day.
Tests nibble paths and proofs of right,
Docs shine formulas in morning light.
Rabbit cheers: options lined up bright!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.20% 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 directly describes the main changes: adding four dropdown shortcuts and formula reference documentation for the Sheets skill.
Description check ✅ Passed The description follows the template with complete Summary, Changes, and Test Plan sections; all required information about the PR objectives is clearly documented.

✏️ 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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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@8104aa3288423e5a0d8bd9252d1080c41d264410

🧩 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

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

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

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

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.go (1)

299-320: Extract duplicated dataValidationRanges mapping into a helper.

The same range-to-{"range": ...} mapping appears in both delete DryRun and Execute. A helper would reduce drift risk.

♻️ Optional refactor
+func buildDataValidationRanges(ranges []interface{}) []interface{} {
+	dvRanges := make([]interface{}, 0, len(ranges))
+	for _, r := range ranges {
+		dvRanges = append(dvRanges, map[string]interface{}{"range": r})
+	}
+	return dvRanges
+}
+
 ...
-		dvRanges := make([]interface{}, 0, len(ranges))
-		for _, r := range ranges {
-			dvRanges = append(dvRanges, map[string]interface{}{"range": r})
-		}
+		dvRanges := buildDataValidationRanges(ranges)
 ...
-		dvRanges := make([]interface{}, 0, len(ranges))
-		for _, r := range ranges {
-			dvRanges = append(dvRanges, map[string]interface{}{"range": r})
-		}
+		dvRanges := buildDataValidationRanges(ranges)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shortcuts/sheets/sheet_dropdown.go` around lines 299 - 320, The mapping that
converts ranges into the slice of maps {"range": r} is duplicated in the DryRun
builder and in Execute; create a small helper function (e.g.,
buildDataValidationRanges or makeDVRanges) that accepts the parsed ranges slice
(type []string or []interface{} matching how ranges is represented) and returns
[]interface{} with each element map[string]interface{}{"range": r}, then replace
the duplicated loops in the DryRun creation and in Execute to call that helper
(update calls in the function literals where dvRanges is currently built).
🤖 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.go`:
- Around line 299-320: The mapping that converts ranges into the slice of maps
{"range": r} is duplicated in the DryRun builder and in Execute; create a small
helper function (e.g., buildDataValidationRanges or makeDVRanges) that accepts
the parsed ranges slice (type []string or []interface{} matching how ranges is
represented) and returns []interface{} with each element
map[string]interface{}{"range": r}, then replace the duplicated loops in the
DryRun creation and in Execute to call that helper (update calls in the function
literals where dvRanges is currently built).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dd466d14-e1e2-41b4-80ec-09749a865a54

📥 Commits

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

📒 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)
  • shortcuts/sheets/shortcuts.go
  • skills/lark-sheets/references/lark-sheets-set-dropdown.md
  • skills/lark-sheets/references/lark-sheets-get-dropdown.md
  • skills/lark-sheets/references/lark-sheets-delete-dropdown.md
  • skill-template/domains/sheets.md
  • skills/lark-sheets/references/lark-sheets-update-dropdown.md
  • skills/lark-sheets/references/lark-sheets-formula.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • skills/lark-sheets/SKILL.md
  • shortcuts/sheets/sheet_dropdown_test.go

@fangshuyu-768 fangshuyu-768 merged commit 76a834e into main Apr 14, 2026
16 checks passed
@fangshuyu-768 fangshuyu-768 deleted the feat/sheet_skill branch April 14, 2026 10:48
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.

2 participants