Skip to content

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

Merged
MaxHuang22 merged 3 commits into
larksuite:mainfrom
MaxHuang22:feat/secret-medallion
Jun 3, 2026
Merged

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

Conversation

@MaxHuang22

@MaxHuang22 MaxHuang22 commented May 26, 2026

Copy link
Copy Markdown
Collaborator

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 to request JSON output (equivalent to --format json) on API, service-method, and shortcut commands; avoids registering duplicate flags where a conflicting flag already exists.
  • Tests

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

@coderabbitai

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a conditional --json boolean flag shorthand for --format json in the shortcut runner and registers the same shorthand on API and service method commands; unit tests validate registration, conflict behavior, and that commands accept --json.

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 registration even 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 and parsing proceeds.
Service command --json support
cmd/service/service.go, cmd/service/service_test.go
Adds --json shorthand flag to generated service method commands and verifies the command executes and the callback receives options.
sequenceDiagram
  participant User
  participant CLI
  participant registerShortcutFlagsWithContext
  participant APICommand
  participant ServiceMethodCommand
  participant Tests
  User->>CLI: run command with `--json`
  CLI->>registerShortcutFlagsWithContext: mount shortcut (register `--json` if enabled)
  registerShortcutFlagsWithContext->>APICommand: add `--json` flag when no conflict
  registerShortcutFlagsWithContext->>ServiceMethodCommand: add `--json` flag when no conflict
  APICommand->>Tests: parsed opts accept `--json`
  ServiceMethodCommand->>Tests: run callback receives options
Loading

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • larksuite/cli#1156: Modifies shortcuts/common/runner.go flag-registration logic and intersects with this PR's --json injection behavior.

Suggested reviewers

  • liangshuo-1

Suggested labels

size/M

Poem

🐰 I nudged a tiny flag with care,
Now --json hops freely through the air,
API and service gave a cheerful cheer,
Shortcuts joined in, the tests all clear,
A rabbit's patch — concise and fair.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% 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 'feat: add --json flag as no-op alias for --format json' clearly and concisely describes the main change in the changeset.
Description check ✅ Passed The description includes all required sections: Summary, Changes, Test Plan, and Related Issues, with comprehensive details about implementation and verification.
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

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown

Actionable comments posted: 0

@github-actions

github-actions Bot commented May 28, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

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

@MaxHuang22
MaxHuang22 force-pushed the feat/secret-medallion branch from 9729b11 to 882be9d Compare May 28, 2026 10:48
@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown

Actionable comments posted: 0

@codecov

codecov Bot commented May 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.22%. Comparing base (57ba4fa) to head (d0cb4bf).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1104   +/-   ##
=======================================
  Coverage   69.21%   69.22%           
=======================================
  Files         634      634           
  Lines       59553    59557    +4     
=======================================
+ Hits        41222    41228    +6     
+ Misses      15012    15011    -1     
+ Partials     3319     3318    -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.

@MaxHuang22
MaxHuang22 force-pushed the feat/secret-medallion branch from 882be9d to 5fc2d9f Compare June 2, 2026 09:05
Skip registration when a custom --json flag already exists on the
command (e.g. base shortcuts use --json for body input).

Change-Id: If66236cadeea7fa81811061cce775deff51b92ce
@MaxHuang22
MaxHuang22 force-pushed the feat/secret-medallion branch from 5fc2d9f to d0cb4bf Compare June 2, 2026 09:21

@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: 1

🤖 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/common/runner_flag_completion_test.go`:
- Around line 150-170: The test
TestShortcutMount_JsonFlag_RegisteredWithoutHasFormat is asserting the opposite
of the shortcut contract: when Shortcut.HasFormat is false the test should
assert that neither the "json" nor the "format" flags are registered after
calling shortcut.Mount(parent, f). Update the assertions to expect
cmd.Flags().Lookup("json") == nil (and similarly for "format") and fail if
either flag is present, so the test verifies that no output-format flags are
added for shortcuts with HasFormat == false.
🪄 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: 6aa9f271-4791-4b72-82f4-897605d190b5

📥 Commits

Reviewing files that changed from the base of the PR and between 5fc2d9f and d0cb4bf.

📒 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
🚧 Files skipped from review as they are similar to previous changes (4)
  • cmd/service/service_test.go
  • cmd/api/api.go
  • shortcuts/common/runner.go
  • cmd/service/service.go

Comment thread shortcuts/common/runner_flag_completion_test.go
@MaxHuang22
MaxHuang22 merged commit 24ce3ec into larksuite:main Jun 3, 2026
18 checks passed
tuxedomm pushed a commit to zhumiaoxin/cli that referenced this pull request Jun 6, 2026
* feat(api): add --json flag as no-op alias for --format json

* feat(service): add --json flag as no-op alias for --format json

* feat(shortcut): add --json flag as no-op alias for --format json

Skip registration when a custom --json flag already exists on the
command (e.g. base shortcuts use --json for body input).

Change-Id: If66236cadeea7fa81811061cce775deff51b92ce
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.

2 participants