Skip to content

feat: add --json flag as no-op alias for --format json#1104

Open
MaxHuang22 wants to merge 3 commits into
larksuite:mainfrom
MaxHuang22:feat/secret-medallion
Open

feat: add --json flag as no-op alias for --format json#1104
MaxHuang22 wants to merge 3 commits into
larksuite:mainfrom
MaxHuang22:feat/secret-medallion

Conversation

@MaxHuang22
Copy link
Copy Markdown
Collaborator

@MaxHuang22 MaxHuang22 commented May 26, 2026

Summary

AI agents frequently pass --json when calling lark-cli commands, causing "unknown flag" errors. This adds --json as a no-op bool flag to api, service, and shortcut (HasFormat) commands so the flag is silently accepted. Since --format already defaults to json, no behavioral wiring is needed.

Changes

  • Add cmd.Flags().Bool("json", ...) to cmd/api/api.go after --format registration
  • Add cmd.Flags().Bool("json", ...) to cmd/service/service.go after --format registration
  • Add cmd.Flags().Bool("json", ...) to shortcuts/common/runner.go inside HasFormat block, with a Lookup("json") guard to skip registration when a custom --json flag already exists (e.g. base domain shortcuts use --json for body input)

Test Plan

  • make unit-test passed
  • validate passed (build + vet + unit + integration)
  • acceptance-reviewer passed (2/2 cases: happy path + edge case)
  • manual verification: lark-cli api GET /open-apis/test --json --dry-run accepted without error; lark-cli calendar +agenda --json --help shows --json flag

Related Issues

N/A

Summary by CodeRabbit

  • New Features

    • Added --json flag as a shorthand for --format json across API, service method, and shortcut commands.
  • Tests

    • Added unit tests to verify the --json flag is correctly registered and accepted in various command contexts.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 43b89206-4542-48f5-8c57-5b787d141295

📥 Commits

Reviewing files that changed from the base of the PR and between b9e5b50 and 68c5eee.

📒 Files selected for processing (6)
  • cmd/api/api.go
  • cmd/api/api_test.go
  • cmd/service/service.go
  • cmd/service/service_test.go
  • shortcuts/common/runner.go
  • shortcuts/common/runner_flag_completion_test.go

📝 Walkthrough

Walkthrough

The PR introduces a --json boolean flag as a shorthand for --format json across the API, service, and shortcut-based command framework. The core framework conditionally registers the flag, while direct command implementations add it to their respective commands, all backed by unit test coverage.

Changes

JSON flag shorthand

Layer / File(s) Summary
Shortcut framework --json flag registration
shortcuts/common/runner.go, shortcuts/common/runner_flag_completion_test.go
Conditionally registers --json as a boolean shorthand in registerShortcutFlagsWithContext when HasFormat is enabled and no conflicting flag exists. Comprehensive tests verify registration when enabled, skipping when custom --json flag conflicts, and absence when HasFormat is disabled.
API command --json support
cmd/api/api.go, cmd/api/api_test.go
Adds --json shorthand flag to the API command and verifies the flag is accepted without error.
Service command --json support
cmd/service/service.go, cmd/service/service_test.go
Adds --json shorthand flag to service method commands and verifies the flag triggers callback with populated options.

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

size/L

Suggested reviewers

  • liangshuo-1

Poem

🐰 A shorthand hops into the CLI,
--json flags dance, oh my oh my,
API, service, shortcuts all align,
With tests to keep the feature fine! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% 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 pull request title accurately and concisely describes the main change: adding a --json flag as a no-op alias for --format json across multiple command types.
Description check ✅ Passed The pull request description follows the required template with complete Summary, Changes, Test Plan, and Related Issues sections. All key details about the motivation, implementation approach, testing verification, and edge cases are well-documented.
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.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch feat/secret-medallion

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 github-actions Bot added the size/L Large or sensitive change across domains or core paths label May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature 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