diff --git a/Cargo.toml b/Cargo.toml index 78b9594..7c4a5eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,4 +31,6 @@ itertools = "0.10.5" flate2 = "1.0.25" csv = "1.1.6" fs_extra = "1.3.0" +lazy_static = "1.4.0" +config = "0.13.3" # spinners = "4.1.0" diff --git a/config/Default.toml b/config/Default.toml new file mode 100644 index 0000000..8b8b170 --- /dev/null +++ b/config/Default.toml @@ -0,0 +1,27 @@ + + +[infer] +min_domain_occurs = 100 +max_ns = 5 +iri_max_length = 200 +min_ns_size = 1000 +iri_trie_size = 1_000_000 +# 2 MIN_DOMAIN_OCCURS +# 4 MAX_NS +# 3 IRI_MAX_LENGTH +# 8 MIN_NS_SIZE +# 3 IRI_TRIE_SIZE + + +[community] +url = "https://raw.githubusercontent.com/linkml/prefixmaps/main/src/prefixmaps/data/merged.csv" +dir = "cache" +path = "cache/prefixmap.json" +# 4 PV_PATH +# 2 PV_URL +# 2 PV_DIR + + +[visulization] +render_dir = "chilon-viz" +# 5 RENDER_DIR diff --git a/src/settings.rs b/src/settings.rs new file mode 100644 index 0000000..24d0fb6 --- /dev/null +++ b/src/settings.rs @@ -0,0 +1,66 @@ +use config::{Config, ConfigError, Environment, File}; + +#[derive(Debug, Deserialize, Clone)] +pub struct Infer { + pub min_domain_occurs: i32, + pub max_ns: i32, + pub iri_max_length: i32, + pub min_ns_size: i32, + pub iri_trie_size: i32, +} + +#[derive(Debug, Deserialize, Clone)] +pub struct Community { + pub url: String, + pub dir: String, + pub path: String, +} + +#[derive(Debug, Deserialize, Clone)] +pub struct Visualization { + pub render_dir: String, +} + +#[derive(Debug, Deserialize, Clone)] +pub struct Settings { + pub infer: Infer, + pub community: Community, + pub visualization: Visualization, + pub env: ENV, +} + +const CONFIG_FILE_PATH: &str = "./config/Default.toml"; +const CONFIG_FILE_PREFIX: &str = "./config/"; + +#[derive(Clone, Debug, Deserialize)] +pub enum ENV { + Development, + Testing, + Production, +} + +impl fmt::Display for ENV { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + ENV::Development => write!(f, "Development"), + ENV::Testing => write!(f, "Testing"), + ENV::Production => write!(f, "Production"), + } + } +} + +impl Settings { + pub fn new() -> Result { + let env = std::env::var("RUN_ENV").unwrap_or_else(|_| "Development".into()); + let mut s = Config::new(); + s.set("env", env.clone())?; + + s.merge(File::with_name(CONFIG_FILE_PATH))?; + s.merge(File::with_name(&format!("{}{}", CONFIG_FILE_PREFIX, env)))?; + + // This makes it so "EA_SERVER__PORT overrides server.port + s.merge(Environment::with_prefix("ea").separator("__"))?; + + s.try_into() + } +}