refactor(cli): co-locate command registration in each command folder#309
refactor(cli): co-locate command registration in each command folder#309rafa-thayto wants to merge 4 commits into
Conversation
🦋 Changeset detectedLatest commit: a7e05c2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Warning Review limit reached
More reviews will be available in 28 minutes and 55 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (18)
📝 WalkthroughWalkthroughThis PR refactors the CLI program architecture by extracting inline command definitions from Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
|
!snapshot |
1a4f549 to
999e72a
Compare
|
Actionable comments posted: 0 |
999e72a to
1a9db1b
Compare
1a9db1b to
569e165
Compare
59dee03 to
ab4de1f
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
packages/cli-core/src/commands/whoami/index.ts (1)
68-78: ⚡ Quick winAdd a focused test for
registerWhoamicommand wiring.This refactor moves registration behavior, so please add/adjust tests that assert
whoamiis registered with--jsonand that the action forwardsoptions.jsonintowhoami({ json }).As per coding guidelines: "
**/*: If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes."🤖 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 `@packages/cli-core/src/commands/whoami/index.ts` around lines 68 - 78, Add a unit test for registerWhoami that verifies the command wiring: instantiate a Command mock/object, call registerWhoami, assert that a "whoami" subcommand exists with the --json option and examples, and spy/mock the whoami function to assert that the command's action calls whoami({ json: options.json }) (i.e., options.json is forwarded). Target the registerWhoami export and the whoami function when creating the test; if no tests are added/modified in the PR, add one per the guideline to cover this behavior.Source: Coding guidelines
packages/cli-core/src/commands/env/index.ts (1)
4-28: ⚡ Quick winAdd command-registration tests for
env pullwiring.Please add coverage for
registerEnv()(command path, options, examples, and.action(pull)binding) so this refactor stays regression-safe.As per coding guidelines: “If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.”
🤖 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 `@packages/cli-core/src/commands/env/index.ts` around lines 4 - 28, Add unit tests that cover registerEnv to prevent regressions: verify the "env" command and its "pull" subcommand are registered with the correct command path and examples, assert the options (--app, --instance, --file) are present on the "pull" command, and confirm the .action handler is bound to the pull function (reference registerEnv and pull). Use the Command test harness or a mocked Command to inspect registered commands/examples/options and assert examples match the array provided in registerEnv so any refactor will fail fast.Source: Coding guidelines
packages/cli-core/src/commands/deploy/index.ts (1)
638-648: ⚡ Quick winAdd registration-focused tests for the new deploy command wiring.
Line 638 introduces new command registration entrypoints (
deploy rundefault +deploy status --wait) but no test changes are included in this review context. Please add/adjust CLI registration tests to assert subcommand visibility/default behavior and--waitoption wiring.As per coding guidelines: "
**/*: If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes."🤖 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 `@packages/cli-core/src/commands/deploy/index.ts` around lines 638 - 648, The new registerDeploy function adds a deploy command with a hidden default subcommand ("deploy run") wired to the deploy handler and a visible "deploy status" with a "--wait" option wired to deployStatus, but there are no tests verifying this wiring; add unit tests that import registerDeploy and assert (1) the top-level "deploy" command exists, (2) "deploy run" is registered as the default/hidden subcommand and triggers the deploy handler, and (3) "deploy status" is registered and exposes the "--wait" option which, when parsed, results in the correct option value being passed to deployStatus; reference registerDeploy, deployCmd, deploy, and deployStatus when locating where to hook the tests.Source: Coding guidelines
🤖 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 `@packages/cli-core/src/commands/env/index.ts`:
- Around line 17-20: Update the command description to reflect actual behavior:
it auto-detects the target env file unless --file is provided rather than always
writing to .env.local. Change the .description(...) text in
packages/cli-core/src/commands/env/index.ts (the description string used for the
pull command) to mention auto-detection and the --file override, and ensure the
wording aligns with the existing pull implementation that selects a target file
when --file is not passed.
---
Nitpick comments:
In `@packages/cli-core/src/commands/deploy/index.ts`:
- Around line 638-648: The new registerDeploy function adds a deploy command
with a hidden default subcommand ("deploy run") wired to the deploy handler and
a visible "deploy status" with a "--wait" option wired to deployStatus, but
there are no tests verifying this wiring; add unit tests that import
registerDeploy and assert (1) the top-level "deploy" command exists, (2) "deploy
run" is registered as the default/hidden subcommand and triggers the deploy
handler, and (3) "deploy status" is registered and exposes the "--wait" option
which, when parsed, results in the correct option value being passed to
deployStatus; reference registerDeploy, deployCmd, deploy, and deployStatus when
locating where to hook the tests.
In `@packages/cli-core/src/commands/env/index.ts`:
- Around line 4-28: Add unit tests that cover registerEnv to prevent
regressions: verify the "env" command and its "pull" subcommand are registered
with the correct command path and examples, assert the options (--app,
--instance, --file) are present on the "pull" command, and confirm the .action
handler is bound to the pull function (reference registerEnv and pull). Use the
Command test harness or a mocked Command to inspect registered
commands/examples/options and assert examples match the array provided in
registerEnv so any refactor will fail fast.
In `@packages/cli-core/src/commands/whoami/index.ts`:
- Around line 68-78: Add a unit test for registerWhoami that verifies the
command wiring: instantiate a Command mock/object, call registerWhoami, assert
that a "whoami" subcommand exists with the --json option and examples, and
spy/mock the whoami function to assert that the command's action calls whoami({
json: options.json }) (i.e., options.json is forwarded). Target the
registerWhoami export and the whoami function when creating the test; if no
tests are added/modified in the PR, add one per the guideline to cover this
behavior.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a16520dd-50da-49a2-a2f4-5b39e514b9d3
📒 Files selected for processing (22)
.changeset/fancy-frogs-open.mdpackages/cli-core/src/cli-program.tspackages/cli-core/src/commands/api/index.tspackages/cli-core/src/commands/apps/index.tspackages/cli-core/src/commands/auth/index.tspackages/cli-core/src/commands/completion/index.tspackages/cli-core/src/commands/config/index.tspackages/cli-core/src/commands/deploy/index.tspackages/cli-core/src/commands/doctor/index.tspackages/cli-core/src/commands/env/index.tspackages/cli-core/src/commands/init/index.tspackages/cli-core/src/commands/link/index.tspackages/cli-core/src/commands/open/index.tspackages/cli-core/src/commands/switch-env/index.tspackages/cli-core/src/commands/toggles/README.mdpackages/cli-core/src/commands/toggles/index.tspackages/cli-core/src/commands/unlink/index.tspackages/cli-core/src/commands/update/index.tspackages/cli-core/src/commands/users/index.tspackages/cli-core/src/commands/whoami/index.tspackages/cli-core/src/lib/option-parsers.test.tspackages/cli-core/src/lib/option-parsers.ts
✅ Files skipped from review due to trivial changes (2)
- .changeset/fancy-frogs-open.md
- packages/cli-core/src/commands/toggles/README.md
🚧 Files skipped from review as they are similar to previous changes (15)
- packages/cli-core/src/commands/api/index.ts
- packages/cli-core/src/commands/switch-env/index.ts
- packages/cli-core/src/lib/option-parsers.ts
- packages/cli-core/src/commands/link/index.ts
- packages/cli-core/src/commands/doctor/index.ts
- packages/cli-core/src/commands/auth/index.ts
- packages/cli-core/src/commands/completion/index.ts
- packages/cli-core/src/commands/unlink/index.ts
- packages/cli-core/src/commands/toggles/index.ts
- packages/cli-core/src/commands/open/index.ts
- packages/cli-core/src/commands/update/index.ts
- packages/cli-core/src/commands/init/index.ts
- packages/cli-core/src/commands/users/index.ts
- packages/cli-core/src/commands/config/index.ts
- packages/cli-core/src/cli-program.ts
Move Commander wiring out of the monolithic cli-program.ts into per-command registerX(program) functions co-located with each command. createProgram() now just calls them in registration order, shrinking cli-program.ts from 1109 to ~320 lines and making each command's surface owned by its own folder. - Each command folder exposes registerX(program): void (mirrors the existing registerExtras precedent) - New commands/toggles/ owns the shared enable/disable parents that wire the orgs + billing handlers (neither feature folder cleanly owns them) - Shared option parsers (parseIntegerOption, collectOptionValues) extracted to lib/option-parsers.ts - clerk --help output verified byte-identical across all 39 command nodes; no user-facing change
…add option-parsers tests Address PR review comments from wyattjoh: - Refactor command registration into a static `registrants` array iterated with a single loop, providing a common/standard registration pattern (comment on cli-program.ts) - Add unit tests for `option-parsers.ts` covering `collectOptionValues` and `parseIntegerOption` (comment on option-parsers.ts) - Also wire in `registerDeploy` for the deploy command added in main and remove the now-deleted `registerSkill` (cleanup after rebase)
ab4de1f to
b8056d9
Compare
…v pull description
What
Splits the command-registration wiring out of the monolithic
packages/cli-core/src/cli-program.ts(1109 lines) into per-commandregisterX(program)functions co-located in each command's folder.createProgram()is now a short, ordered list ofregisterX(program)calls.This makes each command's surface (name, flags, examples, action) owned by its own folder — you add or change a command by editing
commands/<name>/index.ts, not by editing one giant file. It follows the pattern already established byregisterExtras(program).How it works
export function registerX(program: Command): voidholding its own.command()/.option()/.setExamples()/.action()chain (mirrors the existingregisterExtrasprecedent).commands/toggles/owns the sharedenable/disableparents, wiring theorgs+billinghandlers under both (neither feature folder cleanly owns those parents).parseIntegerOption,collectOptionValues) extracted tolib/option-parsers.ts; theusers-onlyUSER_LIST_ORDER_BY_CHOICESmoved into theusersfolder.apps/usersaggregate exports that only existed to feedcli-program.ts.Behavior
No user-facing change. Registration order is preserved exactly, so
clerk --helpand every subcommand's help is unchanged. This was verified by capturing the full--helptree (39 command nodes) frommainbefore the change and diffing it against the result after — byte-identical.Test plan
bun run format— cleanbun run typecheck— cleanbun run lint— 0 warnings, 0 errorsbun run build:compile— compiles (336 modules)bun run test— no new failures introduced (pre-existing local-env failures unchanged vsmain; full verdict from CI)--helptree byte-identical across all 39 nodes (init, auth, link, unlink, whoami, open, apps, users, env, config, enable/disable, api, doctor, switch-env, completion, skill, update, bird)Empty changeset included (internal refactor, no user-facing impact).