use anyhow::Context;
use clap::{Parser, Subcommand};

use folk_builder::{config, runner};

#[derive(Parser)]
#[command(name = "folk-builder", version = "0.1.0")]
struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand)]
enum Commands {
    Build {
        #[arg(short, long, default_value = "folk.build.toml")]
        config: String,
        #[arg(short, long, default_value = ".")]
        output_dir: String,
    },
}

fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();
    let cli = Cli::parse();
    match cli.command {
        Commands::Build { config, output_dir } => {
            let cfg = config::load(&config).with_context(|| format!("load {config}"))?;
            runner::build(&cfg, &output_dir)
        }
    }
}
