feat(sheets): add dropdown shortcuts and formula reference docs#461
feat(sheets): add dropdown shortcuts and formula reference docs#461fangshuyu-768 merged 1 commit intomainfrom
Conversation
📝 WalkthroughWalkthroughAdds four new Lark Sheets dropdown shortcuts— Changes
Sequence DiagramsequenceDiagram
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
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)
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. Comment |
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@8104aa3288423e5a0d8bd9252d1080c41d264410🧩 Skill updatenpx skills add larksuite/cli#feat/sheet_skill -y -g |
Greptile SummaryThis PR adds four dropdown-management shortcuts ( Confidence Score: 5/5
Important Files Changed
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]
Reviews (2): Last reviewed commit: "feat(sheets): add dropdown shortcuts and..." | Re-trigger Greptile |
There was a problem hiding this comment.
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
📒 Files selected for processing (10)
shortcuts/sheets/sheet_dropdown.goshortcuts/sheets/sheet_dropdown_test.goshortcuts/sheets/shortcuts.goskill-template/domains/sheets.mdskills/lark-sheets/SKILL.mdskills/lark-sheets/references/lark-sheets-delete-dropdown.mdskills/lark-sheets/references/lark-sheets-formula.mdskills/lark-sheets/references/lark-sheets-get-dropdown.mdskills/lark-sheets/references/lark-sheets-set-dropdown.mdskills/lark-sheets/references/lark-sheets-update-dropdown.md
abe810e to
c877f72
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
shortcuts/sheets/sheet_dropdown_test.go (1)
6-15: Remove thebytessentinel; 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
📒 Files selected for processing (10)
shortcuts/sheets/sheet_dropdown.goshortcuts/sheets/sheet_dropdown_test.goshortcuts/sheets/shortcuts.goskill-template/domains/sheets.mdskills/lark-sheets/SKILL.mdskills/lark-sheets/references/lark-sheets-delete-dropdown.mdskills/lark-sheets/references/lark-sheets-formula.mdskills/lark-sheets/references/lark-sheets-get-dropdown.mdskills/lark-sheets/references/lark-sheets-set-dropdown.mdskills/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.
c877f72 to
8104aa3
Compare
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
shortcuts/sheets/sheet_dropdown.go (1)
299-320: Extract duplicateddataValidationRangesmapping into a helper.The same range-to-
{"range": ...}mapping appears in both deleteDryRunandExecute. 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
📒 Files selected for processing (10)
shortcuts/sheets/sheet_dropdown.goshortcuts/sheets/sheet_dropdown_test.goshortcuts/sheets/shortcuts.goskill-template/domains/sheets.mdskills/lark-sheets/SKILL.mdskills/lark-sheets/references/lark-sheets-delete-dropdown.mdskills/lark-sheets/references/lark-sheets-formula.mdskills/lark-sheets/references/lark-sheets-get-dropdown.mdskills/lark-sheets/references/lark-sheets-set-dropdown.mdskills/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
Summary
The
multipleValuecell type silently becomes plain text when the target rangehas 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
dataValidationendpoints and documents Lark-specific formula writing rules.Changes
+set-dropdown,+update-dropdown,+get-dropdown,+delete-dropdownshortcuts in
shortcuts/sheets/sheet_dropdown.goshortcuts/sheets/shortcuts.goshortcuts/sheets/sheet_dropdown_test.golark-sheets-{set,update,get,delete}-dropdown.md)lark-sheets-formula.mdreference for ARRAYFORMULA, native arrayfunctions, MAP/LAMBDA, date diff, and unsupported Excel syntax
SKILL.md: add dropdown shortcut table, link formula reference,clarify
multipleValueprerequisiteskill-template/domains/sheets.mdwith latest changesTest Plan
go buildandgo vetpassgo test ./shortcuts/sheets/ -run Dropdown)+set-dropdownwith--multiple --highlight --colors+writewithmultipleValue→ read back confirms dropdown values+get-dropdownreturns correct config+update-dropdownchanges options from 高/中/低 to P0-P3+delete-dropdownremoves config,+get-dropdownconfirms emptycomma in value, colors mismatch, dry-run, no-dropdown range, etc.)
Related Issues
N/A
Summary by CodeRabbit
New Features
Documentation