partiri-cli 0.2.0

Partiri CLI — Deploy and manage services on Partiri Cloud
use inquire::Confirm;
use owo_colors::OwoColorize;

use crate::client::ApiClient;
use crate::config::PartiriConfig;
use crate::error::{CliError, Result};
use crate::output::{ctx, print_success};

pub fn run(client: &ApiClient, config: &PartiriConfig) -> Result<()> {
    let id = config.id_or_err()?;

    if !ctx().yes {
        if ctx().no_input {
            return Err(Box::new(
                CliError::new(
                    "validation",
                    "deploy requires confirmation. Pass --yes (or -y) to skip the prompt.",
                )
                .enriched(),
            ));
        }
        let confirmed = Confirm::new(&format!(
            "Are you sure you want to deploy service {}?",
            id.bold()
        ))
        .with_default(false)
        .prompt()
        .map_err(|_| {
            Box::new(CliError::new("cancelled", "Operation cancelled by user."))
                as crate::error::Error
        })?;

        if !confirmed {
            return Err(Box::new(CliError::new(
                "cancelled",
                "Operation cancelled by user.",
            )));
        }
    }

    client.deploy_service(id)?;

    // Best-effort: pull the latest service state so `deploy_tag` becomes visible
    // once the API has set it. Silent failure is fine — the deploy job runs async,
    // so `deploy_tag` may not exist yet. `partiri llm next` re-checks via job status.
    let _ = crate::modules::service::pull::silent_refresh(client, config);

    print_success("Deploy job created.");
    if !ctx().json {
        println!(
            "\n  Check progress with {}",
            "'partiri service jobs'".bold()
        );
    }

    Ok(())
}