slave 0.2.0

Laravel-inspired CLI for Rust web apps: scaffold Axum projects with built-in auth, users, roles and Turso migrations
use slave_framework::{database, env};

/// Used when `APP_NAME` is not set.
const DEFAULT_NAME: &str = "{{ name }}";

/// Application settings, read from the environment (and `.env`, if present).
#[derive(Debug, Clone)]
pub struct Config {
    pub name: String,
    pub host: String,
    pub port: u16,
    pub database_path: String,
    /// Lifetime of bearer tokens issued at login, in days.
    pub token_ttl_days: u32,
}

impl Config {
    pub fn from_env() -> slave_framework::Result<Self> {
        Ok(Self {
            name: env::var_or("APP_NAME", DEFAULT_NAME),
            host: env::var_or("APP_HOST", "127.0.0.1"),
            port: env::parse_or("APP_PORT", 3000)?,
            database_path: database::path_from_env(),
            token_ttl_days: env::parse_or("AUTH_TOKEN_TTL_DAYS", 30)?,
        })
    }
}