use std::env;
use std::ffi::OsString;
use std::path::PathBuf;
use std::time::Duration;
use tracing::debug;
pub const CAIRO_LS_DB_REPLACE_INTERVAL: &'_ str = "CAIRO_LS_DB_REPLACE_INTERVAL";
pub const CAIRO_LS_LOG: &'_ str = "CAIRO_LS_LOG";
pub const CAIRO_LS_PROFILE: &'_ str = "CAIRO_LS_PROFILE";
pub const SCARB: &'_ str = "SCARB";
pub fn db_replace_interval() -> Duration {
const DEFAULT: u64 = 300;
env::var(CAIRO_LS_DB_REPLACE_INTERVAL)
.ok()
.and_then(|v| v.parse().ok())
.map(Duration::from_secs)
.unwrap_or_else(|| Duration::from_secs(DEFAULT))
}
pub fn log_env_filter() -> String {
env::var(CAIRO_LS_LOG).unwrap_or_default()
}
pub fn tracing_profile() -> bool {
env::var_os(CAIRO_LS_PROFILE).map(env_to_bool).unwrap_or_default()
}
pub fn scarb_path() -> Option<PathBuf> {
env::var_os(SCARB).map(PathBuf::from)
}
pub fn report_to_logs() {
debug!("{CAIRO_LS_DB_REPLACE_INTERVAL}={:?}", db_replace_interval());
debug!("{CAIRO_LS_LOG}={}", log_env_filter());
debug!("{CAIRO_LS_PROFILE}={}", tracing_profile());
debug!("{SCARB}={}", scarb_path().map(|p| p.display().to_string()).unwrap_or_default());
}
fn env_to_bool(os: OsString) -> bool {
matches!(os.to_str(), Some("1") | Some("true"))
}