1use super::config::{BehaviorConfig, Config};
2use once_cell::sync::OnceCell;
3use std::sync::RwLock;
4
5static CONFIG: OnceCell<RwLock<Config>> = OnceCell::new();
7
8pub fn init_config(config: Config) {
10 CONFIG.set(RwLock::new(config)).ok();
11}
12
13pub fn get_date_notation() -> String {
17 if let Ok(notation) = std::env::var("SQL_CLI_DATE_NOTATION") {
19 return notation;
20 }
21
22 CONFIG.get().and_then(|c| c.read().ok()).map_or_else(
23 || "us".to_string(),
24 |c| c.behavior.default_date_notation.clone(),
25 )
26}
27
28pub fn get_behavior_config() -> BehaviorConfig {
30 CONFIG
31 .get()
32 .and_then(|c| c.read().ok())
33 .map(|c| c.behavior.clone())
34 .unwrap_or_default()
35}
36
37pub fn update_config(config: Config) {
39 if let Some(global) = CONFIG.get() {
40 if let Ok(mut c) = global.write() {
41 *c = config;
42 }
43 } else {
44 init_config(config);
45 }
46}