Skip to content

refactor: split cmd/space and cmd/project into per-subcommand files#12

Merged
23prime merged 2 commits intomainfrom
refactor/cmd-directory-structure
Mar 7, 2026
Merged

refactor: split cmd/space and cmd/project into per-subcommand files#12
23prime merged 2 commits intomainfrom
refactor/cmd-directory-structure

Conversation

@23prime
Copy link
Owner

@23prime 23prime commented Mar 7, 2026

Checklist

  • Target branch is main
  • Status checks are passing

Summary

  • src/cmd/space.rssrc/cmd/space/{mod,show,activities,disk_usage,notification}.rs
  • src/cmd/project.rssrc/cmd/project/{mod,list,show}.rs
  • Each subcommand gets its own file with its own tests and MockApi
  • mod.rs holds only module declarations and pub use re-exports
  • main.rs and cmd/mod.rs are unchanged

Reason for change

project will grow to 9 subcommands and issue to 11+. Keeping all logic in a
single 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.rs
  • src/cmd/project/ — 2 subcommand files + mod.rs
  • No behaviour changes; all 71 tests pass

Copilot AI review requested due to automatic review settings March 7, 2026 13:02
@coderabbitai
Copy link

coderabbitai bot commented Mar 7, 2026

Warning

Rate limit exceeded

@23prime has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 15 minutes and 32 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 60821c2b-2f42-4c7b-b844-e4b1482b846c

📥 Commits

Reviewing files that changed from the base of the PR and between 7d099db and 4e59c4d.

📒 Files selected for processing (1)
  • AGENTS.md
📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
Project Command Modularization
src/cmd/project/list.rs, src/cmd/project/show.rs, src/cmd/project/mod.rs
Split project functionality: removed show/show_with/format_project_detail from list.rs and created new show.rs module with these functions. Updated list.rs to expose list/list_with as primary API. Added module declarations and re-exports in mod.rs.
Space Command Modularization
src/cmd/space.rs (removed), src/cmd/space/show.rs, src/cmd/space/activities.rs, src/cmd/space/disk_usage.rs, src/cmd/space/notification.rs, src/cmd/space/mod.rs
Decomposed monolithic space.rs (444 lines) into modular subcommands: show, activities, disk_usage, notification. Each module implements its own public API (function pairs like cmd() and cmd_with()) with text/JSON output formatting and error handling. Module interface consolidates exports via mod.rs.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 From tangled files we hoppy spring,
Each command now its module sings,
No more the monolith's heavy load—
Just tidy paths on modular road! 🌿

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.26% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main refactoring work: splitting monolithic cmd/space and cmd/project files into modular per-subcommand files.
Description check ✅ Passed The pull request description clearly explains the refactoring: splitting cmd/space and cmd/project into per-subcommand files with rationale for the change.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/cmd-directory-structure
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch refactor/cmd-directory-structure

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.rs into src/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 (now src/cmd/project/list.rs) by extracting show into src/cmd/project/show.rs, with a new mod.rs for re-exports.
  • Each test module now uses its own focused MockApi struct 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

Copy link

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

🧹 Nitpick comments (2)
src/cmd/space/show.rs (1)

42-70: Consider extracting a shared MockApi to reduce duplication across subcommand tests.

Each subcommand file (show, activities, disk_usage, notification) defines its own identical MockApi struct implementing all BacklogApi methods. This creates maintenance overhead when the trait evolves—every file needs updating.

A shared test utility (e.g., src/cmd/space/test_support.rs or a #[cfg(test)] module in mod.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 like humansize or 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0b0e3ff and 7d099db.

📒 Files selected for processing (9)
  • src/cmd/project/list.rs
  • src/cmd/project/mod.rs
  • src/cmd/project/show.rs
  • src/cmd/space.rs
  • src/cmd/space/activities.rs
  • src/cmd/space/disk_usage.rs
  • src/cmd/space/mod.rs
  • src/cmd/space/notification.rs
  • src/cmd/space/show.rs
💤 Files with no reviewable changes (1)
  • src/cmd/space.rs

coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 7, 2026
Addresses review comment: update 'Adding a new command' section
@23prime 23prime merged commit a6789f8 into main Mar 7, 2026
10 checks passed
@23prime 23prime deleted the refactor/cmd-directory-structure branch March 7, 2026 13:28
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