zinit 0.3.7

Process supervisor with dependency management
Documentation
//! Example: Get detailed status and stats for a specific service
//!
//! This example shows how to:
//! - Get service status with state, PID, and exit code
//! - Get resource usage (memory, CPU)
//! - Check if service is running
//! - Get dependency information
//!
//! Run with: cargo run --example service_status --features client -- service_name

use std::env;
use zinit::ZinitClient;

fn main() {
    let service_name = env::args()
        .nth(1)
        .unwrap_or_else(|| "zinit-server".to_string());

    println!("Connecting to zinit supervisor...");
    let mut client = match ZinitClient::connect_default() {
        Ok(c) => c,
        Err(e) => {
            eprintln!("✗ Failed to connect: {}", e);
            std::process::exit(1);
        }
    };

    println!("\n=== Service Status: {} ===\n", service_name);

    // Get simplified status
    match client.status(&service_name) {
        Ok(status) => {
            println!("State:      {}", status.state);
            println!("PID:        {}", status.pid);

            if let Some(exit_code) = status.exit_code {
                println!("Exit Code:  {}", exit_code);
            }

            if let Some(error) = status.error {
                println!("Error:      {}", error);
            }
        }
        Err(e) => {
            eprintln!("✗ Failed to get status: {}", e);
            std::process::exit(1);
        }
    }

    // Check if running
    match client.is_running(&service_name) {
        Ok(running) => {
            println!("Running:    {}", if running { "yes" } else { "no" });
        }
        Err(e) => {
            eprintln!("✗ Failed to check if running: {}", e);
        }
    }

    // Get resource stats
    println!("\n=== Resource Usage ===\n");
    match client.stats(&service_name) {
        Ok(stats) => {
            println!("PID:           {}", stats.pid);
            println!(
                "Memory:        {:.2} MB",
                stats.memory_bytes as f64 / 1024.0 / 1024.0
            );
            println!("CPU:           {:.1}%", stats.cpu_percent);
        }
        Err(e) => {
            eprintln!("✗ Failed to get stats: {}", e);
        }
    }

    // Get why blocked (if applicable)
    println!("\n=== Dependencies ===\n");
    match client.why(&service_name) {
        Ok(why) => {
            if why.blocked {
                println!("Status: BLOCKED");
                if !why.waiting_on.is_empty() {
                    println!("Waiting on: {}", why.waiting_on.join(", "));
                }
                if !why.conflicts_with.is_empty() {
                    println!("Conflicts with: {}", why.conflicts_with.join(", "));
                }
            } else {
                println!("Status: NOT BLOCKED");
            }
            if !why.ascii.is_empty() {
                println!("\n{}", why.ascii);
            }
        }
        Err(e) => {
            eprintln!("✗ Failed to get dependency info: {}", e);
        }
    }

    println!("\n✓ Done");
}