1use crate::config::{Config, ConfigError, schema::ConfigModel};
2use std::sync::Arc;
3
4pub fn init_config(toml: &str) -> Result<Arc<ConfigModel>, ConfigError> {
14 parse_and_install_config(toml)
15}
16
17#[must_use]
19pub fn compact_config_source(toml: &str) -> String {
20 let mut compact = String::new();
21
22 for line in toml.lines() {
23 let trimmed = line.trim();
24
25 if trimmed.is_empty() || trimmed.starts_with('#') {
26 continue;
27 }
28
29 compact.push_str(trimmed);
30 compact.push('\n');
31 }
32
33 compact
34}
35
36fn parse_and_install_config(toml: &str) -> Result<Arc<ConfigModel>, ConfigError> {
37 Config::init_from_toml(toml)?;
38
39 Config::try_get().ok_or(ConfigError::NotInitialized)
40}