screeps_rust_api/
utils.rs1#[macro_export]
3macro_rules! screeps_api_from_env {
4 () => {{
5 let _ = dotenvy::dotenv();
6
7 let email = std::env::var("SCREEPS_EMAIL").unwrap_or_else(|_| {
8 eprintln!("SCREEPS_EMAIL not set, using placeholder");
9 "".to_string()
10 });
11
12 let password = std::env::var("SCREEPS_PASSWORD").unwrap_or_else(|_| {
13 eprintln!("SCREEPS_PASSWORD not set, using placeholder");
14 "".to_string()
15 });
16
17 let token = std::env::var("SCREEPS_TOKEN").unwrap_or_else(|_| {
18 eprintln!("SCREEPS_TOKEN not set, using empty string");
19 "".to_string()
20 });
21
22 if std::env::var("SCREEPS_EMAIL").is_err()
24 && std::env::var("SCREEPS_PASSWORD").is_err()
25 && token.is_empty()
26 {
27 eprintln!("No authentication credentials found in environment variables");
28 None
29 } else {
30 let config = $crate::config::ScreepsConfig::new(
31 Some(token),
32 Some(email),
33 Some(password),
34 "screeps.com".to_string(),
35 true,
36 10000,
37 );
38 Some($crate::api::ScreepsApi::new(config))
39 }
40 }};
41}