Skip to main content

execute_command

Function execute_command 

Source
pub async fn execute_command(
    command: Commands,
    output_format: OutputFormat,
) -> Result<ExitCode>
Expand description

Executes the specified CLI command.

Routes commands to their respective handlers. On success, returns the exit code reported by the handler. If the handler fails, the error is printed to stderr and classified into a semantic ExitCode via classify_exit_code rather than propagated — this lets main always turn the result into a process exit code without falling back to anyhow’s default behavior of collapsing every Err to exit code 1.

§Arguments

  • command - The parsed CLI command to execute
  • output_format - Output format preference (JSON, text, or pretty)

§Errors

This function does not propagate command execution failures as Err — see above. It is fallible in signature to match this crate’s convention of using Result consistently across command handlers.

§Examples

use mcp_execution_cli::cli::Commands;
use mcp_execution_cli::runner;
use mcp_execution_core::cli::OutputFormat;

let exit_code = runner::execute_command(
    Commands::Setup,
    OutputFormat::Pretty,
).await?;