1use crate::core::paths::ResolvedPaths;
2use crate::models::domains::shared::ConfigSection;
3use std::sync::Arc;
4
5#[derive(Debug, Clone)]
10pub struct AppContext {
11 pub paths: ResolvedPaths,
12 pub sections: Vec<ConfigSection>,
13 pub root_from_env: bool,
14 pub log_level: Arc<str>,
15 pub file_log_level: Arc<str>,
16 pub verbosity: u8,
17}
18
19impl AppContext {
20 pub fn from_config(config: &crate::database::Config) -> anyhow::Result<Self> {
21 Self::from_config_with_verbosity(config, 0)
22 }
23
24 pub fn from_config_with_verbosity(
25 config: &crate::database::Config,
26 verbosity: u8,
27 ) -> anyhow::Result<Self> {
28 let paths = config.resolved_paths();
29 let sections = config.effective_sections()?.into_iter().collect();
30
31 Ok(Self {
32 paths,
33 sections,
34 root_from_env: config.env.root_override().is_some(),
35 log_level: Arc::from(config.core.log_level.as_str()),
36 file_log_level: Arc::from(config.core.file_log_level.as_str()),
37 verbosity,
38 })
39 }
40}