feat(base): add hidden --field-id-or-name alias for +field-get - #2222
Conversation
|
|
📝 WalkthroughWalkthrough
ChangesField lookup alias
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant CLI
participant BaseFieldGet
participant fieldGetRef
participant FieldAPI
CLI->>BaseFieldGet: provide field-id-or-name
BaseFieldGet->>fieldGetRef: resolve field reference
fieldGetRef->>FieldAPI: construct field endpoint
BaseFieldGet->>FieldAPI: send GET request
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@shortcuts/base/base_shortcuts_test.go`:
- Around line 1212-1220: Strengthen the selector validation assertions in
shortcuts/base/base_shortcuts_test.go:1212-1220 by using errs.ProblemOf to
verify the validation category and subtype, then errors.As with
*errs.ValidationError to verify Param for each relevant BaseFieldGet.Validate
failure. In tests/cli_e2e/base/base_field_get_dryrun_test.go:60-62, retain the
existing validation type and --field-id parameter checks and additionally assert
error.subtype.
In `@shortcuts/base/field_get.go`:
- Around line 62-78: Update fieldGetRef and validateFieldGet to preserve the
original field-id and field-id-or-name values when constructing the request.
Validate whitespace-padded references as invalid with the existing typed
validation error mechanism instead of trimming and silently changing the
selected field.
🪄 Autofix
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 Plus
Run ID: 0b83b52e-6995-44f8-9990-5f56a8aea244
📒 Files selected for processing (6)
shortcuts/base/base_dryrun_ops_test.goshortcuts/base/base_execute_test.goshortcuts/base/base_shortcuts_test.goshortcuts/base/field_get.goshortcuts/base/field_ops.gotests/cli_e2e/base/base_field_get_dryrun_test.go
| if err := BaseFieldGet.Validate(ctx, newBaseTestRuntime(map[string]string{"base-token": "b", "table-id": "t"}, nil, nil)); err == nil || !strings.Contains(err.Error(), "--field-id is required") { | ||
| t.Fatalf("err=%v", err) | ||
| } | ||
| if err := BaseFieldGet.Validate(ctx, newBaseTestRuntime(map[string]string{"base-token": "b", "table-id": "t", "field-id-or-name": "Amount"}, nil, nil)); err != nil { | ||
| t.Fatalf("field get alias validate err=%v", err) | ||
| } | ||
| if err := BaseFieldGet.Validate(ctx, newBaseTestRuntime(map[string]string{"base-token": "b", "table-id": "t", "field-id": "fld_1", "field-id-or-name": "Amount"}, nil, nil)); err == nil || !strings.Contains(err.Error(), "mutually exclusive") { | ||
| t.Fatalf("err=%v", err) | ||
| } |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Assert the typed validation contract.
The new selector validation tests rely partly on error text. Assert the validation category, subtype, and parameter so a change to error classification fails the tests.
shortcuts/base/base_shortcuts_test.go#L1212-L1220: useerrs.ProblemOffor category and subtype, then useerrors.Aswith*errs.ValidationErrorto assertParam.tests/cli_e2e/base/base_field_get_dryrun_test.go#L60-L62: asserterror.subtypein addition to the existing validation type and--field-idparameter.
📍 Affects 2 files
shortcuts/base/base_shortcuts_test.go#L1212-L1220(this comment)tests/cli_e2e/base/base_field_get_dryrun_test.go#L60-L62
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@shortcuts/base/base_shortcuts_test.go` around lines 1212 - 1220, Strengthen
the selector validation assertions in
shortcuts/base/base_shortcuts_test.go:1212-1220 by using errs.ProblemOf to
verify the validation category and subtype, then errors.As with
*errs.ValidationError to verify Param for each relevant BaseFieldGet.Validate
failure. In tests/cli_e2e/base/base_field_get_dryrun_test.go:60-62, retain the
existing validation type and --field-id parameter checks and additionally assert
error.subtype.
Sources: Coding guidelines, Learnings
| func fieldGetRef(runtime *common.RuntimeContext) string { | ||
| if fieldRef := strings.TrimSpace(runtime.Str("field-id")); fieldRef != "" { | ||
| return fieldRef | ||
| } | ||
| return strings.TrimSpace(runtime.Str("field-id-or-name")) | ||
| } | ||
|
|
||
| func validateFieldGet(runtime *common.RuntimeContext) error { | ||
| fieldID := strings.TrimSpace(runtime.Str("field-id")) | ||
| alias := strings.TrimSpace(runtime.Str("field-id-or-name")) | ||
| if fieldID == "" && alias == "" { | ||
| return baseFlagErrorf("--field-id is required") | ||
| } | ||
| if fieldID != "" && alias != "" { | ||
| return baseFlagErrorf("--field-id and --field-id-or-name are mutually exclusive; use --field-id") | ||
| } | ||
| return nil |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Preserve the selected field reference.
strings.TrimSpace changes the field name before the request uses it. This can request a different field. If leading or trailing whitespace is unsupported, return a typed validation error instead of removing it.
Proposed fix
- "strings"
-
"github.com/larksuite/cli/shortcuts/common"
"github.com/spf13/cobra"
@@
func fieldGetRef(runtime *common.RuntimeContext) string {
- if fieldRef := strings.TrimSpace(runtime.Str("field-id")); fieldRef != "" {
+ if fieldRef := runtime.Str("field-id"); fieldRef != "" {
return fieldRef
}
- return strings.TrimSpace(runtime.Str("field-id-or-name"))
+ return runtime.Str("field-id-or-name")
}
func validateFieldGet(runtime *common.RuntimeContext) error {
- fieldID := strings.TrimSpace(runtime.Str("field-id"))
- alias := strings.TrimSpace(runtime.Str("field-id-or-name"))
+ fieldID := runtime.Str("field-id")
+ alias := runtime.Str("field-id-or-name")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@shortcuts/base/field_get.go` around lines 62 - 78, Update fieldGetRef and
validateFieldGet to preserve the original field-id and field-id-or-name values
when constructing the request. Validate whitespace-padded references as invalid
with the existing typed validation error mechanism instead of trimming and
silently changing the selected field.
Source: Coding guidelines
Summary
Add a hidden
--field-id-or-namealias for+field-getso agents can explicitly request a field by ID or name while--field-idremains the canonical selector.Changes
+field-getregisters a hidden--field-id-or-nameflag; it is mutually exclusive with--field-idand at least one selector is required.fieldGetRef.Validate; added a dry-run e2e test for the alias.Test Plan
git diff --checkpassesValidatebehaviortests/cli_e2e/base/base_field_get_dryrun_test.go) verifies the alias request shapemake unit-test/go vet ./...(not run in sync scope)Related Issues
Auto research task: 01KWNBD6WC5QZ2YTZZBB6CTZ37
Summary by CodeRabbit
New Features
Bug Fixes
Tests