partiri-cli 0.2.0

Partiri CLI — Deploy and manage services on Partiri Cloud
use serde::Serialize;
use tabled::Tabled;

use crate::client::ApiClient;
use crate::error::Result;
use crate::output::{ctx, print_table};

#[derive(Tabled, Serialize)]
struct ServiceListRow {
    #[tabled(rename = "Name")]
    name: String,
    #[tabled(rename = "Runtime")]
    runtime: String,
    #[tabled(rename = "Deploy Type")]
    deploy_type: String,
    #[tabled(rename = "ID")]
    id: String,
}

pub fn run_list(client: &ApiClient, project_id: &str) -> Result<()> {
    let services = client.list_services(project_id)?;

    let rows: Vec<ServiceListRow> = services
        .into_iter()
        .map(|s| ServiceListRow {
            name: s.name,
            runtime: s.runtime,
            deploy_type: s.deploy_type,
            id: s.id,
        })
        .collect();

    if rows.is_empty() && !ctx().json {
        println!("No services found in this project.");
        return Ok(());
    }

    print_table(rows);
    Ok(())
}