jana_sessions_webpage/config/src/main.rs

29 lines
718 B
Rust
Raw Normal View History

2025-02-14 03:42:22 +01:00
use config::SessionConfig;
use serde::Serialize;
use std::env;
use std::fs::File;
use std::path::Path;
fn main() {
let out_dir = env::var_os("TRUNK_STAGING_DIR").unwrap_or("target".into());
2025-02-14 03:50:48 +01:00
create_config(
"session_config",
&out_dir,
&SessionConfig {
motd: "Proben Dienstags um 18:30 Uhr und Sonntags um 10:00 Uhr".to_string(),
},
)
2025-02-14 03:42:22 +01:00
}
fn create_config<T, P>(name: &str, out_dir: P, default_config: &T)
2025-02-14 03:50:48 +01:00
where
T: Serialize,
P: AsRef<Path>,
2025-02-14 03:42:22 +01:00
{
//TODO return, if config already exists and is up to date
let out_path = out_dir.as_ref().join(format!("{name}.json"));
let out_file = File::create(&out_path).unwrap();
serde_json::to_writer_pretty(out_file, default_config).unwrap();
2025-02-14 03:50:48 +01:00
}