ufftools 0.1.0

reader/writer and inspect CLI for the UFF character package format. includes the uff decoder lib for use in other projects.
Documentation
mod tools;

use std::{fs, process};
use clap::{Parser, Subcommand};
use ufftools::write_uff;

#[derive(Parser)]
#[command(name = "uff-tools", about = "Work with .uff character packages", version)]
struct Args {
    #[command(subcommand)]
    command: Command,
}

#[derive(Subcommand)]
enum Command {
    /// Inspect a .uff file
    Inspect {
        /// Path to the .uff file
        file: String,
        /// Show full frame and hitbox data for every animation
        #[arg(short, long)]
        verbose: bool,
        /// Restrict output to a single animation by name
        #[arg(short, long, value_name = "NAME")]
        anim: Option<String>,
    },
    /// Write a sample .uff fixture to a file
    Generate {
        /// Output path for the generated .uff file
        file: String,
    },
}

// ── subcommand handlers ──────────────────────────────────────────────────────

fn generate_package(file: &str) {
    let pkg = tools::gen_fixture::generate_fixture();
    let data = write_uff(&pkg).unwrap_or_else(|e| {
        eprintln!("error: failed to encode package: {e}");
        process::exit(1);
    });
    fs::write(file, &data).unwrap_or_else(|e| {
        eprintln!("error: cannot write to \"{file}\": {e}");
        process::exit(1);
    });
    println!("wrote {} bytes to {file}", data.len());
}

// ── main ─────────────────────────────────────────────────────────────────────

fn main() {
    let args = Args::parse();
    match args.command {
        Command::Inspect { file, verbose, anim } => {
            tools::inspect::inspect_package(&file, verbose, anim.as_deref());
        }
        Command::Generate { file } => {
            generate_package(&file);
        }
    }
}