Skip to content

Commit 9748d33

Browse files
committed
Merge #81: Verify issue #64: Template generation and environment creation already split into subcommands
21c3e3a Initial plan (copilot-swe-agent[bot]) Pull request description: Issue #64 requested splitting the create command handler into focused subcommands. This work was already completed in PR #78. ## Current State The refactoring is complete with the following structure: ``` src/presentation/commands/create/ ├── handler.rs (43 lines - routing only) └── subcommands/ ├── template.rs (72 lines) └── environment.rs (271 lines with 5 tests) ``` **Handler now only dispatches:** ```rust pub fn handle_create_command(action: CreateAction, working_dir: &Path) -> Result<(), CreateSubcommandError> { match action { CreateAction::Environment { env_file } => { subcommands::handle_environment_creation(&env_file, working_dir) } CreateAction::Template { output_path } => { let template_path = output_path.unwrap_or_else(CreateAction::default_template_path); subcommands::handle_template_generation(&template_path) } } } ``` ## Verification - Handler reduced from 372 to 43 lines (88% reduction) - Each subcommand independently testable (5 tests in environment, 4 in template) - All 33 create command tests pass - No business logic in router layer - Follows project DDD patterns This PR documents that all acceptance criteria from issue #64 are met. <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Split Template Generation from Environment Creation</issue_title> > <issue_description>**Parent Issue**: #63 > **Type**: 🎯 Quick Win > **Impact**: 🟢🟢🟢 High > **Effort**: 🔵🔵 Medium > **Priority**: P0 > **Depends On**: #64 (Proposal 1) > > ## Problem > > The `handle_create_command()` function handles two completely different concerns in a single file, making it large (372 lines) and mixing different levels of abstraction: > > ```rust > pub fn handle_create_command(action: CreateAction, working_dir: &Path) { > match action { > CreateAction::Environment { env_file } => { > // Complex domain operation (100+ lines) > handle_environment_creation(&env_file, working_dir) > } > CreateAction::Template { output_path } => { > // Simple file operation (30 lines) > handle_template_generation(&template_path) > } > } > } > ``` > > ## Proposed Solution > > Separate the subcommand implementations into their own modules: > > **Structure:** > ``` > create/ > ├── handler.rs // Simple router (delegates to subcommands) > ├── subcommands/ > │ ├── mod.rs > │ ├── template.rs // Template generation logic > │ └── environment.rs // Environment creation logic > └── ... > ``` > > **Router in `handler.rs`:** > ```rust > use super::subcommands; > > pub fn handle_create_command(action: CreateAction, working_dir: &Path) > -> Result<(), CreateSubcommandError> > { > match action { > CreateAction::Environment { env_file } => { > subcommands::environment::handle(&env_file, working_dir) > } > CreateAction::Template { output_path } => { > let template_path = output_path.unwrap_or_else(CreateAction::default_template_path); > subcommands::template::handle(&template_path) > } > } > } > ``` > > ## Benefits > > - ✅ Router stays focused on dispatching (single responsibility) > - ✅ Each subcommand has its own focused module > - ✅ Easier to test each subcommand independently > - ✅ Aligns with Proposal 1's subcommands folder structure > - ✅ Reduces file size from 372 lines to manageable modules > - ✅ Prepares for future refactoring of environment creation > > ## Implementation Checklist > > - [ ] Create `src/presentation/commands/create/subcommands/` directory > - [ ] Create `src/presentation/commands/create/subcommands/mod.rs` > - [ ] Extract template generation to `subcommands/template.rs` with `handle()` function > - [ ] Extract environment creation to `subcommands/environment.rs` with `handle()` function > - [ ] Extract `display_success_message()` helper to template subcommand > - [ ] Add comprehensive documentation to each subcommand module > - [ ] Update `create/mod.rs` to include subcommands module > - [ ] Update `handler.rs` to import and delegate to subcommands > - [ ] Update re-exports if needed > - [ ] Move or duplicate relevant tests to subcommand modules > - [ ] Verify all tests pass > - [ ] Run linter and fix issues > > ## Acceptance Criteria > > - [ ] Template generation is in `subcommands/template.rs` > - [ ] Environment creation is in `subcommands/environment.rs` > - [ ] Router in `handler.rs` only dispatches (no business logic) > - [ ] Each subcommand is independently testable > - [ ] All functionality is preserved > - [ ] All tests pass: `cargo test create::subcommands` > - [ ] Pre-commit checks pass: `./scripts/pre-commit.sh` > - [ ] Code follows project conventions > > ## Related Documentation > > - [Module Organization Guide](https://github.com/torrust/torrust-tracker-deployer/blob/main/docs/contributing/module-organization.md) > - [Refactor Plan](https://github.com/torrust/torrust-tracker-deployer/blob/main/docs/refactors/plans/presentation-commands-cleanup.md)</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> - Fixes #67 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/torrust/torrust-tracker-deployer/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. ACKs for top commit: josecelano: ACK 21c3e3a Tree-SHA512: 90070cf4f66baccfd762bc82cf30b8dd450b885b2b2f6ee6bd813d336af7a9aa6914b831aa7f88d59b1913476167b9096d695f1a5206069507ac44f6b1370b10
2 parents 5d5726e + 21c3e3a commit 9748d33

0 file changed

File tree

    0 commit comments

    Comments
     (0)