2025-10-18 11:38:19 -07:00
|
|
|
#![doc = include_str!("../README.md")]
|
|
|
|
|
|
|
|
|
|
mod error;
|
2025-11-08 12:26:24 -08:00
|
|
|
|
2025-11-27 10:03:34 +00:00
|
|
|
#[cfg(feature = "decimal")]
|
|
|
|
|
pub mod decimal;
|
|
|
|
|
|
2025-10-18 11:38:19 -07:00
|
|
|
pub use error::*;
|
2025-12-12 02:09:57 +00:00
|
|
|
pub use modrinth_log as log;
|
2025-10-18 11:38:19 -07:00
|
|
|
|
|
|
|
|
use eyre::{Result, eyre};
|
|
|
|
|
|
|
|
|
|
/// Fetches an environment variable, possibly loading it using [`dotenvy`].
|
|
|
|
|
///
|
|
|
|
|
/// # Errors
|
|
|
|
|
///
|
|
|
|
|
/// Errors if the environment variable is missing or empty, providing a
|
|
|
|
|
/// pretty-printed error including the environment variable name.
|
|
|
|
|
#[track_caller]
|
|
|
|
|
pub fn env_var(key: &str) -> Result<String> {
|
|
|
|
|
let value = dotenvy::var(key)
|
|
|
|
|
.wrap_err_with(|| eyre!("missing environment variable `{key}`"))?;
|
|
|
|
|
if value.is_empty() {
|
|
|
|
|
Err(eyre!("environment variable `{key}` is empty"))
|
|
|
|
|
} else {
|
|
|
|
|
Ok(value)
|
|
|
|
|
}
|
|
|
|
|
}
|