Skip to content

feat: unconditionally inject --format flag for all shortcuts#1156

Open
MaxHuang22 wants to merge 3 commits into
mainfrom
feat/shortcut-format-universal
Open

feat: unconditionally inject --format flag for all shortcuts#1156
MaxHuang22 wants to merge 3 commits into
mainfrom
feat/shortcut-format-universal

Conversation

@MaxHuang22
Copy link
Copy Markdown
Collaborator

@MaxHuang22 MaxHuang22 commented May 28, 2026

Summary

--format flag was only injected for shortcuts that explicitly set HasFormat: true, leaving ~190 shortcuts without output format control. This PR removes the three HasFormat guards in runner.go so every shortcut gets --format unconditionally. Shortcuts that already define a custom format flag in Flags[] (e.g. mail +triage, mail +watch) are skipped via Lookup("format") == nil to avoid redefinition panics. HasFormat is retained in the struct but marked deprecated.

Changes

  • shortcuts/common/runner.go: remove three if s.HasFormat guards; add cmd.Flags().Lookup("format") == nil check before auto-injection to skip shortcuts with custom format flags
  • shortcuts/common/types.go: mark HasFormat field as Deprecated:
  • shortcuts/common/runner_format_universal_test.go (new): verify HasFormat: false shortcut still receives --format after mount

Test Plan

  • make unit-test passed
  • validate passed (build / vet / unit / integration all green)
  • local-eval passed (E2E N/A lite mode, skillave N/A)
  • acceptance-reviewer passed (2/2 cases)
  • manual verification: lark-cli calendar +rsvp --help--format now present; lark-cli calendar +agenda --format table --dry-run — no regression

Related Issues

N/A

Summary by CodeRabbit

  • New Features

    • The --format flag is now universally available for all shortcuts, defaulting to "json" for consistent output.
  • Tests

    • Added a test that verifies the --format flag is always registered regardless of shortcut configuration.
  • Documentation

    • Marked the per-shortcut "HasFormat" indicator as deprecated since it no longer affects flag injection.

Review Change Stack

Removes three HasFormat guards in runner.go so every shortcut
gets --format regardless of the Shortcut.HasFormat field value.
Shortcuts that already define a custom 'format' flag in Flags[]
are skipped to avoid redefinition panics (e.g. mail +triage, +watch).
HasFormat is retained in the struct but marked deprecated.

Change-Id: I5e8fe07e839d5aed4cefaf7d753dabbaee68fb6e
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 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: a1bb4a7b-51b9-43ab-9654-fd1b9d8434b6

📥 Commits

Reviewing files that changed from the base of the PR and between cd2b359 and 7e94722.

📒 Files selected for processing (1)
  • shortcuts/common/runner_format_universal_test.go
💤 Files with no reviewable changes (1)
  • shortcuts/common/runner_format_universal_test.go

📝 Walkthrough

Walkthrough

The shortcut framework now always injects and reads the --format flag; Shortcut.HasFormat is deprecated. Flag registration avoids duplicates. A new unit test asserts format is present with default "json" even when HasFormat is false.

Changes

Universal Format Flag

Layer / File(s) Summary
Format types and runtime read
shortcuts/common/types.go, shortcuts/common/runner.go
Shortcut.HasFormat comment marked deprecated; newRuntimeContext always reads --format into rctx.Format.
Flag registration and completion
shortcuts/common/runner.go
registerShortcutFlagsWithContext registers --format only if it doesn't already exist and adds shell completion; keeps conditional --yes for high-risk shortcuts and always registers --jq before adding the shortcut identity flag.
Format flag registration test
shortcuts/common/runner_format_universal_test.go
New test TestShortcutMount_FormatFlagAlwaysRegistered mounts a Shortcut with HasFormat: false and asserts the mounted +message-send command has a format flag with default value "json".

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I hop through flags both far and near,
--format now present, crisp and clear,
HasFormat whispers, "deprecated" and small,
JSON defaults steady for one and all,
A rabbit cheers for consistency 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 specifically summarizes the main change: unconditionally injecting the --format flag for all shortcuts.
Description check ✅ Passed The PR description includes all required template sections with comprehensive information: summary of motivation, detailed changes list, complete test plan with verification steps, and related issues section.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/shortcut-format-universal

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/M Single-domain feat or fix with limited business impact label May 28, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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_format_universal_test.go`:
- Around line 17-18: Add environment isolation by calling
t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir()) at the start of the test
before interacting with cmdutil.TestFactory; specifically, insert t.Setenv(...)
prior to the line calling cmdutil.TestFactory(t, nil) (the t variable in the
test) so the test uses an isolated config dir instead of shared state.
🪄 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: 274a54cb-8903-47be-b699-c8737cfbd0d6

📥 Commits

Reviewing files that changed from the base of the PR and between 893555a and 996112a.

📒 Files selected for processing (3)
  • shortcuts/common/runner.go
  • shortcuts/common/runner_format_universal_test.go
  • shortcuts/common/types.go

Comment thread shortcuts/common/runner_format_universal_test.go
@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.74%. Comparing base (b91f6a2) to head (7e94722).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1156      +/-   ##
==========================================
+ Coverage   68.63%   68.74%   +0.11%     
==========================================
  Files         625      627       +2     
  Lines       58386    58577     +191     
==========================================
+ Hits        40071    40267     +196     
+ Misses      15027    15018       -9     
- Partials     3288     3292       +4     

☔ 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.

@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@7e947222cd0e4648e2e1f4026718cec024659226

🧩 Skill update

npx skills add larksuite/cli#feat/shortcut-format-universal -y -g

Change-Id: I3a59942aa8a6753cd949ca42f2a19a72f032ff55
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Actionable comments posted: 0

Change-Id: I0146e5a2f57f5419863bdeeaa1a662fd8f70bddf
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Actionable comments posted: 0

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

Labels

feature size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant