xbp 10.28.0

XBP is a zero-config build pack that can also interact with proxies, kafka, sockets, synthetic monitors.
Documentation
use crate::cli::commands;
use crate::cli::error::{CliResult, ErrorFactory};
use crate::cli::ui;
use crate::commands::{
    install_api_service, run_api_daemons, run_api_health, run_api_jobs, run_api_projects,
    run_api_request, run_api_routes,
};
use crate::logging::{log_error, log_success};

pub async fn handle_api(cmd: commands::ApiCmd, debug: bool) -> CliResult<()> {
    match cmd.command {
        commands::ApiSubCommand::Install { port } => {
            if let Err(e) = ui::with_loader(
                &format!("Installing xbp-api.service on port {}", port),
                install_api_service(port, debug),
            )
            .await
            {
                let _ = log_error("api", "API systemd install failed", Some(&e)).await;
                return Err(ErrorFactory::operation(
                    "api",
                    "install xbp-api.service",
                    e,
                    Some("Check systemd availability and permissions, then retry."),
                ));
            }
            let _ = log_success(
                "api",
                &format!("xbp-api.service installed on port {}", port),
                None,
            )
            .await;
        }
        commands::ApiSubCommand::Health(health_cmd) => {
            if let Err(e) = run_api_health(&health_cmd).await {
                let _ = log_error("api", "API health request failed", Some(&e)).await;
                return Err(ErrorFactory::operation(
                    "api",
                    "run API health request",
                    e,
                    Some("Check `API_XBP_URL`, `XBP_API_TOKEN`, or use `--base-url` / `--web`."),
                ));
            }
        }
        commands::ApiSubCommand::Projects(projects_cmd) => {
            if let Err(e) = run_api_projects(&projects_cmd).await {
                let _ = log_error("api", "Projects API command failed", Some(&e)).await;
                return Err(ErrorFactory::operation(
                    "api",
                    "run projects API command",
                    e,
                    Some("Check the project payload and configured API base URL."),
                ));
            }
        }
        commands::ApiSubCommand::Daemons(daemons_cmd) => {
            if let Err(e) = run_api_daemons(&daemons_cmd).await {
                let _ = log_error("api", "Daemons API command failed", Some(&e)).await;
                return Err(ErrorFactory::operation(
                    "api",
                    "run daemons API command",
                    e,
                    Some("Check the daemon payload and configured API base URL."),
                ));
            }
        }
        commands::ApiSubCommand::Jobs(jobs_cmd) => {
            if let Err(e) = run_api_jobs(&jobs_cmd).await {
                let _ = log_error("api", "Deployment jobs API command failed", Some(&e)).await;
                return Err(ErrorFactory::operation(
                    "api",
                    "run deployment jobs API command",
                    e,
                    Some("Check the job payload, IDs, and configured API base URL."),
                ));
            }
        }
        commands::ApiSubCommand::Routes(routes_cmd) => {
            if let Err(e) = run_api_routes(&routes_cmd).await {
                let _ = log_error("api", "Routes API command failed", Some(&e)).await;
                return Err(ErrorFactory::operation(
                    "api",
                    "run routes API command",
                    e,
                    Some("Routes usually need a local API base such as `--base-url http://127.0.0.1:8080`."),
                ));
            }
        }
        commands::ApiSubCommand::Request(request_cmd) => {
            if let Err(e) = run_api_request(&request_cmd).await {
                let _ = log_error("api", "API request failed", Some(&e)).await;
                return Err(ErrorFactory::operation(
                    "api",
                    "run API request",
                    e,
                    Some("Check `API_XBP_URL`, `XBP_API_TOKEN`, the path, and request body."),
                ));
            }
        }
    }
    Ok(())
}