refactor: split cmd/space and cmd/project into per-subcommand files#12
refactor: split cmd/space and cmd/project into per-subcommand files#12
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR refactors CLI command structure by splitting monolithic command modules into modular subcommands. Project commands are separated from combined list.rs into distinct list and show modules; space commands are split from a single 444-line file into dedicated activities, disk_usage, notification, and show modules, each with its own public interface. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
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 |
There was a problem hiding this comment.
Pull request overview
This PR refactors two command modules (space and project) from single-file modules into per-subcommand directory layouts. This is a purely structural change with no behavior modifications, preparing the codebase for future growth (9 project subcommands and 11+ issue subcommands as noted in the description).
Changes:
- Split
src/cmd/space.rsintosrc/cmd/space/{mod,show,activities,disk_usage,notification}.rs, with each subcommand in its own file containing its logic and tests. - Split
src/cmd/project.rs(nowsrc/cmd/project/list.rs) by extractingshowintosrc/cmd/project/show.rs, with a newmod.rsfor re-exports. - Each test module now uses its own focused
MockApistruct instead of a shared one with fields for all subcommands.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/cmd/space.rs |
Deleted — all code moved to per-subcommand files under src/cmd/space/ |
src/cmd/space/mod.rs |
New module declarations and pub use re-exports for 4 subcommands |
src/cmd/space/show.rs |
Space show subcommand logic and tests extracted from old space.rs |
src/cmd/space/activities.rs |
Activities subcommand logic and tests extracted from old space.rs |
src/cmd/space/disk_usage.rs |
Disk usage subcommand logic and tests extracted from old space.rs |
src/cmd/space/notification.rs |
Notification subcommand logic and tests extracted from old space.rs |
src/cmd/project/mod.rs |
New module declarations and pub use re-exports for list and show |
src/cmd/project/show.rs |
Project show subcommand logic and tests extracted from old project.rs |
src/cmd/project/list.rs |
Removed show-related code; format_project_row moved into test scope |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/cmd/space/show.rs (1)
42-70: Consider extracting a sharedMockApito reduce duplication across subcommand tests.Each subcommand file (show, activities, disk_usage, notification) defines its own identical
MockApistruct implementing allBacklogApimethods. This creates maintenance overhead when the trait evolves—every file needs updating.A shared test utility (e.g.,
src/cmd/space/test_support.rsor a#[cfg(test)]module inmod.rs) with a configurable mock could reduce this duplication significantly.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/cmd/space/show.rs` around lines 42 - 70, Extract the duplicated MockApi into a shared test helper (e.g., add a src/cmd/space/test_support.rs or a #[cfg(test)] mod in the parent module) that exposes a configurable MockApi implementing crate::api::BacklogApi; replace the per-file MockApi definitions in show.rs (the MockApi struct and its impl of BacklogApi) and the identical mocks in activities, disk_usage, notification tests with imports from this shared helper so tests reuse the same mock and only customize the Option<Space> or other injected fields as needed.src/cmd/space/disk_usage.rs (1)
24-36: Optional UX enhancement: human-readable byte formatting.Raw byte values (e.g.,
5242880 bytes) can be hard to scan for large spaces. A helper likehumansizeor a simple KB/MB/GB formatter could improve readability in text mode while keeping JSON output unchanged.This is purely a nice-to-have for future consideration.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/cmd/space/disk_usage.rs` around lines 24 - 36, Replace raw byte integers with human-readable sizes in format_disk_usage_text: introduce or use a helper (e.g., a humansize formatter or a simple bytes_to_human function) and call it for usage.capacity, usage.issue, usage.wiki, usage.file, usage.subversion, usage.git, and usage.git_lfs before formatting the string in format_disk_usage_text; leave usage.details.len() as-is and do not change JSON output paths elsewhere. Ensure the helper is available in the module (add a small helper or a dependency like humansize) and update the format string to reflect the human-readable values.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/cmd/space/disk_usage.rs`:
- Around line 24-36: Replace raw byte integers with human-readable sizes in
format_disk_usage_text: introduce or use a helper (e.g., a humansize formatter
or a simple bytes_to_human function) and call it for usage.capacity,
usage.issue, usage.wiki, usage.file, usage.subversion, usage.git, and
usage.git_lfs before formatting the string in format_disk_usage_text; leave
usage.details.len() as-is and do not change JSON output paths elsewhere. Ensure
the helper is available in the module (add a small helper or a dependency like
humansize) and update the format string to reflect the human-readable values.
In `@src/cmd/space/show.rs`:
- Around line 42-70: Extract the duplicated MockApi into a shared test helper
(e.g., add a src/cmd/space/test_support.rs or a #[cfg(test)] mod in the parent
module) that exposes a configurable MockApi implementing crate::api::BacklogApi;
replace the per-file MockApi definitions in show.rs (the MockApi struct and its
impl of BacklogApi) and the identical mocks in activities, disk_usage,
notification tests with imports from this shared helper so tests reuse the same
mock and only customize the Option<Space> or other injected fields as needed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 99fe8475-deba-491a-956c-8ddaec0d6d40
📒 Files selected for processing (9)
src/cmd/project/list.rssrc/cmd/project/mod.rssrc/cmd/project/show.rssrc/cmd/space.rssrc/cmd/space/activities.rssrc/cmd/space/disk_usage.rssrc/cmd/space/mod.rssrc/cmd/space/notification.rssrc/cmd/space/show.rs
💤 Files with no reviewable changes (1)
- src/cmd/space.rs
Addresses review comment: update 'Adding a new command' section
Checklist
mainSummary
src/cmd/space.rs→src/cmd/space/{mod,show,activities,disk_usage,notification}.rssrc/cmd/project.rs→src/cmd/project/{mod,list,show}.rsMockApimod.rsholds only module declarations andpub usere-exportsmain.rsandcmd/mod.rsare unchangedReason for change
projectwill grow to 9 subcommands andissueto 11+. Keeping all logic in asingle file per command group would result in 1000+ line files. Splitting by
subcommand keeps each file focused and makes future additions straightforward.
Changes
src/cmd/space/— 4 subcommand files +mod.rssrc/cmd/project/— 2 subcommand files +mod.rs