Skip to main content

harmont_cli/commands/
mod.rs

1pub mod run;
2
3use anyhow::Result;
4
5use crate::cli::Command;
6use crate::context::RunContext;
7
8/// Dispatch a parsed CLI command to the appropriate handler. Returns an exit code.
9///
10/// # Errors
11///
12/// Returns an error if the dispatched handler returns one. The exact set
13/// of failures depends on the command (filesystem/Docker for `run`,
14/// plugin-registry IO for `plugin`, plugin runtime errors for `external`).
15pub async fn dispatch(command: Command, ctx: RunContext) -> Result<i32> {
16    match command {
17        Command::Run(args) => run::handle(args, ctx).await,
18        Command::Version => crate::builtin::version::run().await.map(|()| 0),
19        Command::Plugin(cmd) => crate::builtin::plugin::run(cmd).await.map(|()| 0),
20        Command::External(argv) => crate::dispatcher::run(argv).await,
21    }
22}