Skip to main content

route_command

Function route_command 

Source
pub async fn route_command(
    command: Commands,
    working_dir: &Path,
    context: &ExecutionContext,
) -> Result<(), CommandError>
Expand description

Route a parsed command to its appropriate handler

This function serves as the central dispatch point for all CLI commands. It takes a parsed command and an execution context, then routes the command to the appropriate handler function in the Controllers layer.

§Arguments

  • command - Parsed command from the Input Layer
  • working_dir - Working directory for command execution
  • context - Execution context providing access to application services

§Returns

Returns Ok(()) on successful command execution, or a CommandError if the command fails. The error contains detailed context and actionable troubleshooting information.

§Errors

Returns an error if:

  • Command handler execution fails
  • Required services are not available in the context
  • Command parameters are invalid

§Examples

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

async fn example() -> Result<(), Box<dyn std::error::Error>> {
    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 - requires proper Commands construction
    // route_command(command, working_dir, &context).await?;
    Ok(())
}