zinit 0.3.7

Process supervisor with dependency management
Documentation
//! Example: List all services and their status
//!
//! This example demonstrates how to connect to the zinit supervisor
//! and list all available services with their current status.
//!
//! Run with: cargo run --example list_services --features client

use zinit::ZinitClient;

fn main() {
    // Connect to the supervisor using the default socket path
    // On Linux: /run/zinit.sock
    // On macOS/Windows: $HOME/hero/var/zinit.sock
    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);
        }
    };

    // Ping the supervisor to verify connection
    match client.ping() {
        Ok(ping_response) => {
            println!("✓ Connected (version: {})\n", ping_response.version);
        }
        Err(e) => {
            eprintln!("✗ Failed to ping supervisor: {}", e);
            std::process::exit(1);
        }
    }

    // List all service names
    println!("Fetching service list...");
    let services = match client.list() {
        Ok(s) => s,
        Err(e) => {
            eprintln!("✗ Failed to list services: {}", e);
            std::process::exit(1);
        }
    };

    if services.is_empty() {
        println!("No services found.");
        return;
    }

    println!("Found {} services:\n", services.len());
    println!("{:<30} {:<15} {:<10}", "NAME", "STATE", "PID");
    println!("{:-<55}", "");

    // Get status for each service
    for service_name in services {
        match client.status(&service_name) {
            Ok(status) => {
                let pid_str = if status.pid > 0 {
                    status.pid.to_string()
                } else {
                    "-".to_string()
                };
                println!(
                    "{:<30} {:<15} {:<10}",
                    service_name,
                    status.state.to_string(),
                    pid_str
                );
            }
            Err(e) => {
                println!("{:<30} {:<15} {:<10}", service_name, "ERROR", e);
            }
        }
    }

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