luff 0.2.1

Print files with formatting
Documentation
//! CLI entry point for luff with config file and schema generation support

use luff::cli::{Args, Commands};

fn main() -> miette::Result<()> {
    // Parse arguments first to determine log level and command
    let args = Args::parse_args();

    // Handle schema generation subcommand (early exit, before logger setup)
    if let Some(Commands::Schema { .. }) = args.command() {
        // Don't initialize logger for schema generation
        return Ok(luff::cli::run(&args)?);
    }

    // Initialize logger based on verbosity flag
    let log_level = if args.verbose() { "debug" } else { "info" };
    env_logger::Builder::from_env(env_logger::Env::default().default_filter_or(log_level))
        .format_timestamp(None)
        .format_target(false)
        .init();

    // Run the CLI with parsed arguments
    if let Err(e) = luff::cli::run(&args) {
        // Handle broken pipe (SIGPIPE) gracefully for unix pipelines (e.g. `luff | head`)
        if let luff::Error::Io(io_err) = &e {
            if io_err.kind() == std::io::ErrorKind::BrokenPipe {
                return Ok(());
            }
        }
        return Err(e.into());
    }

    Ok(())
}