errcraft 0.1.0

Beautiful, structured, and colorful error handling for Rust.
Documentation
//! Example demonstrating various CLI output options and styles.

use errcraft::{BacktraceMode, ColorMode, DisplayOptions, ErrFrame};

fn create_sample_error() -> ErrFrame {
    let io_err = std::io::Error::new(std::io::ErrorKind::PermissionDenied, "Permission denied");

    ErrFrame::new("Failed to write configuration")
        .context("file", "/etc/myapp/config.toml")
        .context("user", "alice")
        .context("permissions", "0644")
        .context_text("Requires write access to system directory")
        .with_source(io_err)
        .capture_backtrace()
}

fn main() {
    println!("=== errcraft CLI Output Example ===\n");

    let err = create_sample_error();

    // Example 1: Default output
    println!("Example 1: Default output (auto-detect colors)");
    println!("{}", "".repeat(60));
    err.eprint();
    println!("{}\n", "".repeat(60));

    // Example 2: Force colors
    println!("Example 2: Force colored output");
    println!("{}", "".repeat(60));
    let opts = DisplayOptions::new()
        .with_color(ColorMode::Always)
        .with_emoji(true);
    println!("{}", err.to_string_styled(&opts));
    println!("{}\n", "".repeat(60));

    // Example 3: No colors
    println!("Example 3: Plain output (no colors)");
    println!("{}", "".repeat(60));
    let opts = DisplayOptions::new()
        .with_color(ColorMode::Never)
        .with_emoji(false);
    println!("{}", err.to_string_styled(&opts));
    println!("{}\n", "".repeat(60));

    // Example 4: With emoji but no colors
    println!("Example 4: Emoji without colors");
    println!("{}", "".repeat(60));
    let opts = DisplayOptions::new()
        .with_color(ColorMode::Never)
        .with_emoji(true);
    println!("{}", err.to_string_styled(&opts));
    println!("{}\n", "".repeat(60));

    // Example 5: Limited depth
    println!("Example 5: Limited error depth (max 1 level)");
    println!("{}", "".repeat(60));
    let opts = DisplayOptions::new()
        .with_color(ColorMode::Never)
        .with_max_depth(Some(1));
    println!("{}", err.to_string_styled(&opts));
    println!("{}\n", "".repeat(60));

    // Example 6: With backtrace (if RUST_BACKTRACE=1)
    println!("Example 6: With backtrace (set RUST_BACKTRACE=1 to see)");
    println!("{}", "".repeat(60));
    let opts = DisplayOptions::new()
        .with_color(ColorMode::Never)
        .with_backtrace(BacktraceMode::Auto);
    println!("{}", err.to_string_styled(&opts));
    println!("{}\n", "".repeat(60));

    // Example 7: JSON output (if serde feature enabled)
    #[cfg(feature = "serde")]
    {
        println!("Example 7: JSON output");
        println!("{}", "".repeat(60));
        println!("{}", err.to_json_string());
        println!("{}\n", "".repeat(60));
    }

    // Example 8: Markdown output (if markdown feature enabled)
    #[cfg(feature = "markdown")]
    {
        println!("Example 8: Markdown output");
        println!("{}", "".repeat(60));
        println!("{}", err.to_markdown());
        println!("{}\n", "".repeat(60));
    }
}