Skip to main content

Module router

Expand description

Command Router

This module provides the central command routing functionality for the Dispatch Layer. It contains the route_command function that matches parsed CLI commands to their appropriate handler functions.

§Purpose

The router extracts command dispatch logic from the main application bootstrap and the presentation commands module, creating a clean separation between:

  • Command parsing (Input Layer - already done)
  • Command routing (This module - routes commands to handlers)
  • Command execution (Controller Layer - executes business logic)
  • Result presentation (View Layer - displays results)

§Design

Commands enum → route_command() → Handler function
     ↓                ↓                    ↓
Parsed input    Route decision      Business logic

§Benefits

  • Centralized Routing: All command routing logic in one place
  • Type Safety: Compile-time guarantees that all commands are handled
  • Testability: Router can be tested independently of handlers
  • Maintainability: Easy to add new commands or modify routing logic

§Usage Example

use std::path::Path;
use std::sync::Arc;
use torrust_tracker_deployer_lib::bootstrap::Container;
use torrust_tracker_deployer_lib::presentation::cli::dispatch::{route_command, ExecutionContext};
use torrust_tracker_deployer_lib::presentation::cli::views::VerbosityLevel;
// Note: Commands enum requires specific action parameters in practice

let container = Container::new(VerbosityLevel::Normal);
let context = ExecutionContext::new(Arc::new(container), global_args);
let working_dir = Path::new(".");

// Route command to appropriate handler
// Note: Commands require proper construction with actions

Functions§

route_command
Route a parsed command to its appropriate handler