Skip to content

Commit

Permalink
add warning for broken cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
Kezii committed Mar 16, 2024
1 parent 0e4be28 commit a716c0e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
12 changes: 0 additions & 12 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
#[toml_cfg::toml_config]
pub struct Config {
#[default("")]
wifi_ssid: &'static str,
#[default("")]
wifi_psk: &'static str,
#[default("")]
bot_token: &'static str,
#[default(0)]
owner_id: i64,
}

fn main() {
// Check if the `cfg.toml` file exists and has been filled out.
if !std::path::Path::new("cfg.toml").exists() {
Expand Down
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use log::info;
#[derive(Debug)]
#[toml_cfg::toml_config]
pub struct Config {
#[default("")]
Expand All @@ -11,5 +13,11 @@ pub struct Config {
}

pub fn get_config() -> Config {
info!("got config {:#?}", CONFIG);

if CONFIG.wifi_ssid.is_empty() && CONFIG.wifi_psk.is_empty() {
panic!("WiFi SSID and PSK are not set\nif you use --target-dir the toml was not loaded, check this issue https://github.com/jamesmunns/toml-cfg/issues/7");
}

CONFIG
}

0 comments on commit a716c0e

Please sign in to comment.