Skip to main content

agent_can/cli/
mod.rs

1pub mod args;
2pub mod commands;
3pub mod error;
4pub mod output;
5
6use crate::cli::args::CliArgs;
7use crate::cli::commands::to_request;
8use crate::cli::error::CliError;
9use crate::connection::execute_request;
10use std::process::ExitCode;
11
12pub async fn run_with_args(args: CliArgs) -> ExitCode {
13    match run_inner(args).await {
14        Ok(code) => code,
15        Err(err) => {
16            eprintln!("{err}");
17            ExitCode::from(1)
18        }
19    }
20}
21
22async fn run_inner(args: CliArgs) -> Result<ExitCode, CliError> {
23    let request = to_request(&args)?;
24    let response = execute_request(request)
25        .await
26        .map_err(|err| CliError::CommandFailed(err.to_string()))?;
27    output::print_response(&response, args.json);
28    if response.success {
29        Ok(ExitCode::SUCCESS)
30    } else {
31        Ok(ExitCode::from(1))
32    }
33}