From 4c9beea15fcd02e400911a1773230ee62355c3cf Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 22 Jun 2023 19:10:54 +0200 Subject: [PATCH] Start work on updating `micronfig` --- Cargo.lock | 7 +++-- Cargo.toml | 2 +- src/config/mod.rs | 80 ++++++++++++++++++++++------------------------- 3 files changed, 43 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fa7eb81..325de11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -992,9 +992,12 @@ dependencies = [ [[package]] name = "micronfig" -version = "0.1.2" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d5fa5735feed9ff4d6fc550793ef80d18b90f33f3f89af6176318f295383cd" +checksum = "caf3c1187adebdc5ad8ca94618b966fe8f40e4a3c80fa2f3eaee47891b410156" +dependencies = [ + "lazy_static", +] [[package]] name = "mime" diff --git a/Cargo.toml b/Cargo.toml index ab3733f..b228134 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ hmac = { version = "0.12.1", optional = true } sha2 = { version = "0.10.6", optional = true } # exec pretty_env_logger = { version = "0.4.0", optional = true } -micronfig = { version = "0.1.2", optional = true } +micronfig = { version = "0.2.0", optional = true } # data serde = { version = "1.0.140", features = ["derive"] } serde_json = { version = "1.0.82" } diff --git a/src/config/mod.rs b/src/config/mod.rs index fe3f86a..48dc87c 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -5,61 +5,55 @@ /// Configuration required by the `exec` feature. #[cfg(feature = "exec")] pub mod exec { - lazy_static::lazy_static! { - /// The locale that card data should be downloaded in. - /// - /// # Examples - /// - /// - `en_US` - /// - `it_IT` - /// - pub static ref DATA_DRAGON_LOCALE: String = - micronfig::required("DATA_DRAGON_LOCALE"); - /// The set codes for which card data should be downloaded, separated by commas. - /// - /// # Examples - /// - /// - `set1,set2,set3` - /// - `set1` - /// - `set1,set2,set3,set4,set5,set6,set6cde,set7` - /// - pub static ref DATA_DRAGON_SET_CODES: Vec = - micronfig::required::("DATA_DRAGON_SET_CODES") - .split(",").map(|s: &str| s.to_string()).collect(); - } + /// The locale that card data should be downloaded in. + /// + /// # Examples + /// + /// - `en_US` + /// - `it_IT` + /// + micronfig::required!(DATA_DRAGON_LOCALE, String); + + /// The set codes for which card data should be downloaded, separated by commas. + /// + /// # Examples + /// + /// - `set1,set2,set3` + /// - `set1` + /// - `set1,set2,set3,set4,set5,set6,set6cde,set7` + /// + micronfig::required!(DATA_DRAGON_SET_CODES, String); } /// Configuration required by the `jpg` feature. #[cfg(feature = "jpg")] pub mod jpg { - lazy_static::lazy_static! { - /// Secret key configured in imgproxy. - pub static ref POROXY_KEY: Vec = micronfig::required("POROXY_KEY"); - /// Salt configured in imgproxy. - pub static ref POROXY_SALT: String = micronfig::required("POROXY_SALT"); + /// Secret key configured in imgproxy. + micronfig::required!(POROXY_KEY, Vec); - /// URL where imgproxy can be reached at. - pub static ref POROXY_HOST: String = micronfig::required("POROXY_HOST"); - } + /// Salt configured in imgproxy. + micronfig::required!(POROXY_SALT, String); + + /// URL where imgproxy can be reached at. + micronfig::required!(POROXY_HOST, String); } /// Configuration required by the `discord` feature. #[cfg(feature = "discord")] pub mod discord { - lazy_static::lazy_static! { - /// ID of the guild where commands should be registered in. - /// - /// If not defined, commands are registered globally, and then cached. - /// - /// Useful for development, since guild commands are not cached. - pub static ref SERENITY_DEV_GUILD_ID: Option = micronfig::optional("SERENITY_DEV_GUILD_ID").map(|s: u64| s.into()); - /// The Discord bot token. - pub static ref SERENITY_TOKEN: String = micronfig::required("SERENITY_TOKEN"); - - /// The Discord bot app ID. - pub static ref SERENITY_APPID: u64 = micronfig::required("SERENITY_APPID"); - } + /// ID of the guild where commands should be registered in. + /// + /// If not defined, commands are registered globally, and then cached. + /// + /// Useful for development, since guild commands are not cached. + micronfig::optional!(SERENITY_DEV_GUILD_ID, serenity::model::id::GuildId); + + /// The Discord bot token. + micronfig::required!(SERENITY_TOKEN, String); + + /// The Discord bot app ID. + micronfig::required!(SERENITY_APPID, u64); } \ No newline at end of file