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 a boolean --json shorthand for requesting --format json across API, service-method, and shortcut commands; registration is conditional to avoid conflicts with existing flags.
  • Tests

    • Added unit tests validating the --json flag is registered when applicable, skipped on conflicts, and accepted by relevant commands.

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: a6b16528-97e8-4f01-b1d9-449a3bd9d8eb

📥 Commits

Reviewing files that changed from the base of the PR and between 9729b11 and 882be9d.

📒 Files selected for processing (4)
  • cmd/service/service.go
  • cmd/service/service_test.go
  • shortcuts/common/runner.go
  • shortcuts/common/runner_flag_completion_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • shortcuts/common/runner.go
  • cmd/service/service_test.go
  • shortcuts/common/runner_flag_completion_test.go
  • cmd/service/service.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. Tests verify registration when enabled, skipping when a 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 runs the command and delivers options to the callback.

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

size/L

Suggested reviewers

  • liangshuo-1

Poem

🐰 I hopped through flags both near and far,
A tiny --json now shines like a star,
API and service cheer with delight,
Shortcuts hum softly into the night,
Tests nod and say, "This feels just right."

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% 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 accurately describes the main change: adding a --json flag as a no-op alias for --format json.
Description check ✅ Passed The description follows the template structure with all required sections: Summary, Changes, Test Plan (with checkboxes showing passing tests), and Related Issues.
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

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
@MaxHuang22 MaxHuang22 force-pushed the feat/secret-medallion branch from 68c5eee to 9729b11 Compare May 28, 2026 10:30
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Actionable comments posted: 0

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 28, 2026

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@882be9da73cba6c8ee3296f7a1ee963c52780cf6

🧩 Skill update

npx skills add MaxHuang22/cli#feat/secret-medallion -y -g

Skip registration when a custom --json flag already exists on the
command (e.g. base shortcuts use --json for body input).
@MaxHuang22 MaxHuang22 force-pushed the feat/secret-medallion branch from 9729b11 to 882be9d Compare May 28, 2026 10:48
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Actionable comments posted: 0

@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.64%. Comparing base (3cd84fc) to head (882be9d).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1104   +/-   ##
=======================================
  Coverage   68.64%   68.64%           
=======================================
  Files         625      625           
  Lines       58389    58393    +4     
=======================================
+ Hits        40079    40082    +3     
- Misses      15023    15025    +2     
+ Partials     3287     3286    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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