chyabrung-cli 0.2.2

The `chy` command line tool for Chyabrung: scaffolding, dev server with hot reload, builds, generators, migrations and one-command deploys
//! Starts the app: loads `.env`, connects the database (DB_* settings), runs migrations and
//! serves on the host and port from `chyabrung.toml`. You rarely need to edit this.

use chyabrung::prelude::*;

#[tokio::main]
async fn main() {
    chyabrung::config::load_dotenv();

    let db = Db::connect_env().await;
    let migrated = match {{crate_name}}::migrator() {
        Ok(m) => m.run(&db).await.map(|_| ()),
        Err(e) => Err(e),
    };
    if let Err(e) = migrated {
        eprintln!("migrations failed: {e}");
        std::process::exit(1);
    }

    let jwt = match Jwt::from_env() {
        Ok(j) => j,
        Err(e) => {
            eprintln!("{e}");
            std::process::exit(1);
        }
    };
    let cache = Cache::from_env().await.unwrap_or_else(|_| Cache::memory());
    // FILESYSTEM_DISK in .env: `local` (storage/public, served at /storage) or `s3` (AWS_* settings).
    let storage = match chyabrung::storage::Storage::from_env_or_local("storage/public", "/storage") {
        Ok(s) => s,
        Err(e) => {
            eprintln!("{e}");
            std::process::exit(1);
        }
    };

    // Host and port come from chyabrung.toml (APP_HOST / APP_PORT override them).
    {{crate_name}}::app(db, jwt, cache, storage).serve().await;
}