//! Website server binary entry point

use clap::Parser;
use rustelo_htmx_server::run::run_main;

#[derive(Parser)]
#[command(name = "website")]
struct Args {
    /// Path to the site NCL configuration file.
    /// Falls back to NCL_CONFIG_PATH, then SITE_CONFIG_PATH env vars.
    #[arg(long, env = "NCL_CONFIG_PATH")]
    config: Option<std::path::PathBuf>,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let args = Args::parse();
    let config = args
        .config
        .or_else(|| std::env::var("SITE_CONFIG_PATH").ok().map(std::path::PathBuf::from))
        .unwrap_or_else(|| {
            panic!(
                "\n\nNo site configuration path provided.\n\
                 Set one of:\n\
                 \n  --config <path>          (CLI argument)\
                 \n  NCL_CONFIG_PATH=<path>   (env var)\
                 \n  SITE_CONFIG_PATH=<path>  (env var)\n"
            )
        });
    // Propagate for runtime resource loading (e.g., FooterLoader, MenuLoader)
    std::env::set_var("NCL_CONFIG_PATH", &config);
    run_main()
}
