Skip to content

feat(base): add hidden --field-id-or-name alias for +field-get - #2222

Open
TanDianxiong wants to merge 1 commit into
larksuite:mainfrom
TanDianxiong:auto-research-sync/01KWNBD6WC5QZ2YTZZBB6CTZ37/mr-948-d8299934
Open

feat(base): add hidden --field-id-or-name alias for +field-get#2222
TanDianxiong wants to merge 1 commit into
larksuite:mainfrom
TanDianxiong:auto-research-sync/01KWNBD6WC5QZ2YTZZBB6CTZ37/mr-948-d8299934

Conversation

@TanDianxiong

@TanDianxiong TanDianxiong commented Aug 6, 2026

Copy link
Copy Markdown

Summary

Add a hidden --field-id-or-name alias for +field-get so agents can explicitly request a field by ID or name while --field-id remains the canonical selector.

Changes

  • +field-get registers a hidden --field-id-or-name flag; it is mutually exclusive with --field-id and at least one selector is required.
  • Dry-run and execute paths resolve the field reference from either flag via fieldGetRef.
  • Added unit tests for the hidden flag, flag-group (one-required / mutual exclusion) behavior, and Validate; added a dry-run e2e test for the alias.

Test Plan

  • git diff --check passes
  • New unit tests cover flag registration, group validation, and alias Validate behavior
  • New dry-run e2e test (tests/cli_e2e/base/base_field_get_dryrun_test.go) verifies the alias request shape
  • CI: make unit-test / go vet ./... (not run in sync scope)

Related Issues

Auto research task: 01KWNBD6WC5QZ2YTZZBB6CTZ37

Summary by CodeRabbit

  • New Features

    • Field retrieval now accepts either a field ID or field name.
    • Field names are resolved into the appropriate API request and returned field details.
  • Bug Fixes

    • Added validation requiring exactly one field selector.
    • Invalid requests now provide clear errors when no selector or multiple selectors are supplied.
  • Tests

    • Expanded coverage for name-based lookup, dry runs, validation, and hidden command options.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

BaseFieldGet now accepts either --field-id or hidden --field-id-or-name. It validates that exactly one selector is set, trims the value, and uses it for dry-run and execution requests. Tests cover lookup, validation, help output, and endpoint generation.

Changes

Field lookup alias

Layer / File(s) Summary
Field selector contract
shortcuts/base/field_get.go, shortcuts/base/base_shortcuts_test.go
BaseFieldGet adds the hidden --field-id-or-name selector. Validation requires one selector, rejects both selectors, and trims the selected reference.
Request reference resolution
shortcuts/base/field_ops.go
Dry-run and execution paths use fieldGetRef(runtime) when constructing field requests.
Alias behavior coverage
shortcuts/base/base_dryrun_ops_test.go, shortcuts/base/base_execute_test.go, tests/cli_e2e/base/base_field_get_dryrun_test.go
Tests verify name-based endpoints, returned field data, hidden help output, and structured validation errors.

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
Loading

Possibly related PRs

  • larksuite/cli#2153: Both PRs modify BaseFieldGet to support hidden field-reference aliases.
  • larksuite/cli#2219: Both PRs add and validate the hidden --field-id-or-name alias through fieldGetRef.

Suggested labels: domain/base, size/M

Suggested reviewers: zgz2048

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding a hidden field selector alias for +field-get.
Description check ✅ Passed The description covers the summary, changes, tests, and related work; it also states which checks were not run.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@github-actions github-actions Bot added domain/base PR touches the base domain size/M Single-domain feat or fix with limited business impact labels Aug 6, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between f7d0326 and b89933d.

📒 Files selected for processing (6)
  • shortcuts/base/base_dryrun_ops_test.go
  • shortcuts/base/base_execute_test.go
  • shortcuts/base/base_shortcuts_test.go
  • shortcuts/base/field_get.go
  • shortcuts/base/field_ops.go
  • tests/cli_e2e/base/base_field_get_dryrun_test.go

Comment on lines +1212 to +1220
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)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 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: use errs.ProblemOf for category and subtype, then use errors.As with *errs.ValidationError to assert Param.
  • tests/cli_e2e/base/base_field_get_dryrun_test.go#L60-L62: assert error.subtype in addition to the existing validation type and --field-id parameter.
📍 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

Comment on lines +62 to +78
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 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

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

Labels

domain/base PR touches the base domain size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants