oph 0.1.0

OpenHealth CLI - Universal development tool for the OpenHealth team
Documentation
use colored::Colorize;
use dialoguer::Confirm;
use indicatif::{ProgressBar, ProgressStyle};
use std::time::Duration;

/// Print an info message (cyan)
pub fn info(msg: &str) {
    println!("{}", msg.cyan());
}

/// Print a success message (green)
pub fn success(msg: &str) {
    println!("{}", msg.green());
}

/// Print a warning message (yellow)
pub fn warning(msg: &str) {
    println!("{}", msg.yellow());
}

/// Print an error message (red)
pub fn error(msg: &str) {
    eprintln!("{}", msg.red());
}

/// Print a header with separators
pub fn header(title: &str) {
    let separator = "=".repeat(title.len() + 4);
    println!("{}", separator.cyan());
    println!("  {}", title.cyan().bold());
    println!("{}", separator.cyan());
}

/// Create a spinner with a message
pub fn spinner(msg: &str) -> ProgressBar {
    let pb = ProgressBar::new_spinner();
    pb.set_style(
        ProgressStyle::default_spinner()
            .template("{spinner:.cyan} {msg}")
            .unwrap()
            .tick_chars("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"),
    );
    pb.set_message(msg.to_string());
    pb.enable_steady_tick(Duration::from_millis(80));
    pb
}

/// Ask for confirmation before a dangerous operation
pub fn confirm_dangerous(msg: &str) -> bool {
    println!("{} {}", "WARNING:".red().bold(), msg.red());
    Confirm::new()
        .with_prompt("Are you sure?")
        .default(false)
        .interact()
        .unwrap_or(false)
}

/// Ask for strict confirmation (must type "yes")
pub fn confirm_strict(msg: &str) -> bool {
    println!("{} {}", "WARNING:".red().bold(), msg.red());
    println!("Type '{}' to confirm:", "yes".yellow());

    let mut input = String::new();
    if std::io::stdin().read_line(&mut input).is_err() {
        return false;
    }

    input.trim().to_lowercase() == "yes"
}

/// Print a step indicator
pub fn step(num: usize, total: usize, msg: &str) {
    println!("{} {}", format!("[{num}/{total}]").cyan().bold(), msg);
}

/// Print a list item
pub fn list_item(key: &str, value: &str) {
    println!("  {} {}", format!("{key}:").green(), value);
}

/// Print a command that will be executed
pub fn show_command(cmd: &str) {
    println!("{} {}", "$".dimmed(), cmd.dimmed());
}