p2p_chat/ui/runner/actions/execute.rs
1//! This module contains the logic for executing chat commands.
2use anyhow::Result;
3
4use super::{commands, context::CommandContext};
5
6/// Executes a chat command.
7///
8/// This function parses a command line string and dispatches it to the
9/// appropriate command handler.
10///
11/// # Arguments
12///
13/// * `cmd_line` - The full command line string entered by the user.
14/// * `context` - The `CommandContext` providing access to the application's state.
15///
16/// # Returns
17///
18/// A `Result` indicating success or failure of the command execution.
19pub(super) async fn execute_chat_command(cmd_line: &str, context: CommandContext) -> Result<()> {
20 let parts: Vec<&str> = cmd_line.split_whitespace().collect();
21 if parts.is_empty() {
22 return Ok(());
23 }
24
25 commands::dispatch(&parts, &context).await
26}