use libremetaverse_codegen::{regenerate, regenerate_to, vendor_inputs, workspace_root};
use std::path::Path;

fn main() {
    let arguments: Vec<String> = std::env::args().skip(1).collect();
    let root = workspace_root();
    let result = match arguments.as_slice() {
        [command] if command == "generate" => regenerate(&root, false),
        [command] if command == "check" => regenerate(&root, true),
        [command, output] if command == "generate-to" => regenerate_to(&root, Path::new(output)),
        [command, reference] if command == "vendor" => vendor_inputs(&root, Path::new(reference)),
        _ => Err(
            "usage: libremetaverse-codegen <generate|check|generate-to OUTPUT_ROOT|vendor REFERENCE_CHECKOUT>".to_owned(),
        ),
    };
    if let Err(error) = result {
        eprintln!("{error}");
        std::process::exit(2);
    }
}
