Skip to content

refactor(cli): extract command handler boundaries - #173

Merged
errfld merged 2 commits into
mainfrom
gh-164/command-handler-boundaries
Jun 25, 2026
Merged

refactor(cli): extract command handler boundaries#173
errfld merged 2 commits into
mainfrom
gh-164/command-handler-boundaries

Conversation

@errfld

@errfld errfld commented Jun 25, 2026

Copy link
Copy Markdown
Owner

Summary

  • Extract install, init, and run command orchestration from main.rs into focused commands modules.
  • Move init template ownership and hook stdin buffering helpers behind the command-handler boundary.
  • Keep main.rs responsible for CLI parsing, config path resolution, and top-level dispatch while preserving command behavior.

Refs #164

Validation

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo test --workspace --all-targets --all-features
  • Manual smoke in a temporary Git repository: git smee init, git smee install, git smee doctor, git smee doctor --json, git smee status, git smee status --json; parsed JSON status values were ok.

Summary by CodeRabbit

  • New Features

    • Added CLI support for initializing configs with selectable templates.
    • Added a dedicated install command with progress messages.
    • Added a hook-run command that handles hook input and reports execution results.
  • Bug Fixes

    • Improved validation so commands must run from the repository root.
    • Added limits for hook input size to prevent unexpectedly large payloads.
  • Refactor

    • Simplified the main CLI entrypoint by moving command logic into separate command handlers.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@errfld, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 52 minutes and 30 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0ef51e2d-dda5-4eaf-80ef-b53015499b67

📥 Commits

Reviewing files that changed from the base of the PR and between b7e82dd and 21076a7.

📒 Files selected for processing (1)
  • crates/git-smee-cli/src/commands/run.rs
📝 Walkthrough

Walkthrough

git-smee-cli now routes init, install, and run through separate command modules. Init adds selectable starter templates and managed config writing. Install and run each handle repository validation, config loading, hook execution, and hook stdin limiting.

Changes

CLI command split

Layer / File(s) Summary
Command surface and dispatch
crates/git-smee-cli/src/commands/mod.rs, crates/git-smee-cli/src/main.rs
commands/mod.rs declares the command modules, and main.rs routes init, install, and run subcommands to the new entrypoints.
Init templates and config install
crates/git-smee-cli/src/commands/init.rs
InitTemplate adds selectable starter configs, run_init writes managed config content, and tests cover template names and hook sections.
Install command entrypoint
crates/git-smee-cli/src/commands/install.rs
run_install checks repository root, resolves the config path for hook scripts, loads the config, and installs hooks with status output.
Hook execution and stdin handling
crates/git-smee-cli/src/commands/run.rs
run_hook loads hook stdin only when needed, enforces the stdin byte limit from the environment, executes the hook summary, and tests the limit display format.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

  • Issue 164: The command split into commands/init.rs, commands/install.rs, and commands/run.rs matches the issue’s module-refactoring objective.

Possibly related PRs

  • errfld/git-smee#23: The init/install flow here also uses managed headers and forced writes when handling generated config content.
  • errfld/git-smee#153: Both changes cover the hook execution path that prints and acts on hook summaries.
  • errfld/git-smee#166: Both PRs add git-smee init starter templates and template-name handling.

Poem

🐇 I hopped through modules, neat and light,
with templates warm and hooks in sight.
I sniffed the stdin, small and trim,
then bounded back with summaries dim.
Hoppy configs! The burrow sings,
as git-smee darts on swift new springs.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the CLI refactor that extracts command handling into dedicated boundaries.
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
  • Commit unit tests in branch gh-164/command-handler-boundaries

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.

@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 `@crates/git-smee-cli/src/commands/run.rs`:
- Around line 52-57: The stdin sentinel read in run() can overflow when
max_hook_stdin_bytes() returns u64::MAX, causing a panic in debug or a wrapped
zero limit in release. Update the .take(max_hook_stdin_bytes + 1) logic to use
checked_add(1) or a u64::MAX special-case before read_to_end, and keep the
over-limit detection behavior intact in the run command path.
🪄 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: ASSERTIVE

Plan: Pro

Run ID: c804b15a-8882-40ee-ad9a-65a53f7c8550

📥 Commits

Reviewing files that changed from the base of the PR and between a35d608 and b7e82dd.

📒 Files selected for processing (5)
  • crates/git-smee-cli/src/commands/init.rs
  • crates/git-smee-cli/src/commands/install.rs
  • crates/git-smee-cli/src/commands/mod.rs
  • crates/git-smee-cli/src/commands/run.rs
  • crates/git-smee-cli/src/main.rs

Comment thread crates/git-smee-cli/src/commands/run.rs
@errfld
errfld merged commit 9d3033d into main Jun 25, 2026
28 checks passed
@errfld
errfld deleted the gh-164/command-handler-boundaries branch June 25, 2026 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants