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 PodRow {
    #[tabled(rename = "Name")]
    name: String,
    #[tabled(rename = "Label")]
    label: String,
    #[tabled(rename = "CPU")]
    cpu: String,
    #[tabled(rename = "RAM")]
    ram: String,
    #[tabled(rename = "ID")]
    id: String,
}

pub fn run_list(client: &ApiClient, workspace_id: &str) -> Result<()> {
    let pods = client.list_pods(workspace_id)?;

    let rows: Vec<PodRow> = pods
        .into_iter()
        .map(|p| PodRow {
            name: p.name,
            label: p.label.unwrap_or_default(),
            cpu: p.cpu.unwrap_or_default(),
            ram: p.ram.unwrap_or_default(),
            id: p.id,
        })
        .collect();

    if rows.is_empty() && !ctx().json {
        println!("No compute pods available in this workspace.");
        return Ok(());
    }

    print_table(rows);
    Ok(())
}