use std::path::{Path, PathBuf};
use clap::ValueEnum;
use enum_map::{Enum, EnumMap};
use strum_macros::{EnumIter, EnumString, IntoStaticStr, VariantNames};
#[derive(
Debug,
ValueEnum,
EnumString,
VariantNames,
EnumIter,
IntoStaticStr,
PartialEq,
Eq,
PartialOrd,
Copy,
Clone,
)]
pub enum OddityHandling {
Ignore,
Warn,
Error,
}
impl Default for OddityHandling {
fn default() -> Self {
Self::Warn
}
}
impl OddityHandling {
pub const fn ignore(self) -> bool {
matches!(self, Self::Ignore)
}
}
#[derive(Clone, Copy, Debug, Enum, EnumIter)]
pub enum RDProperty {
Range,
Domain,
}
impl RDProperty {
pub const fn to_str(self) -> &'static str {
match self {
Self::Range => "range",
Self::Domain => "domain",
}
}
}
#[derive(Clone, Debug, Default)]
pub struct Settings {
pub and_list_detected: EnumMap<RDProperty, OddityHandling>,
pub style_mix_property: EnumMap<RDProperty, OddityHandling>,
pub style_mix_ontology: EnumMap<RDProperty, OddityHandling>,
}
#[derive(Clone, Debug)]
pub struct Config {
pub settings: Settings,
pub base_iri: Option<String>,
pub owl: PathBuf,
pub shacl: Option<PathBuf>,
pub prefixes: Option<PathBuf>,
}
impl Config {
fn insert_postfix(orig: Option<PathBuf>, base: &Path, postfix: &str) -> PathBuf {
orig.unwrap_or_else(|| {
let file_name_orig = base.file_name().unwrap();
let file_name_new = file_name_orig
.to_string_lossy()
.as_ref()
.replace(".ttl", &format!("-{postfix}.ttl"));
base.with_file_name(file_name_new)
})
}
pub fn shacl(&self) -> PathBuf {
Self::insert_postfix(self.shacl.clone(), &self.owl, "shacl")
}
pub fn prefixes(&self) -> PathBuf {
Self::insert_postfix(
self.prefixes.clone(),
self.shacl.as_ref().unwrap_or(&self.owl),
"prefixes",
)
}
}