diff --git a/src/cli.rs b/src/cli.rs index 6f574ee..d258298 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -101,6 +101,8 @@ pub enum SubCommand { #[arg(long = "strict", help = "Strikter Vergleich des Inhalts")] strict: bool, }, + #[command(about = "Überprüfe OSC-Datei auf bekannte Fehler")] + Check { file: String }, #[cfg(feature = "unzip-osb")] #[command(about = "Entpackt eine OSB-Datei")] UnzipOsb { diff --git a/src/main.rs b/src/main.rs index dab6d8a..f34d635 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,6 +40,7 @@ use sha256::digest; use crate::cli::{Cli, SubCommand}; use crate::model::onkostar_editor::OnkostarEditor; +use crate::model::Checkable; use crate::profile::Profile; mod cli; @@ -257,6 +258,12 @@ fn main() -> Result<(), Box> { } }; } + SubCommand::Check { file } => { + read_inputfile(file)? + .check() + .iter() + .for_each(|check_notice| println!("{}", check_notice)); + } #[cfg(feature = "unzip-osb")] SubCommand::UnzipOsb { file, diff --git a/src/model/mod.rs b/src/model/mod.rs index eed540c..98d056a 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -24,7 +24,7 @@ use std::cmp::Ordering; use std::collections::hash_map::DefaultHasher; -use std::fmt::Debug; +use std::fmt::{Debug, Display, Formatter}; use std::hash::{Hash, Hasher}; use crate::model::requirements::Requires; @@ -329,3 +329,25 @@ pub trait FolderContent { "ONKOSTAR Bibliothek" == self.get_library_folder() } } + +pub enum CheckNotice { + /// This will result in Error if importing file + Error { code: String, description: String }, + /// Other known issues + Warning { description: String }, +} + +impl Display for CheckNotice { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + CheckNotice::Error { code, description } => { + write!(f, "[ERROR] ({}) {}", code, description) + } + CheckNotice::Warning { description } => write!(f, "[WARNING] {}", description), + } + } +} + +pub trait Checkable { + fn check(&self) -> Vec; +} diff --git a/src/model/onkostar_editor.rs b/src/model/onkostar_editor.rs index 051f84a..20a4df8 100644 --- a/src/model/onkostar_editor.rs +++ b/src/model/onkostar_editor.rs @@ -35,7 +35,9 @@ use crate::model::data_form::DataForm; use crate::model::property_catalogue::PropertyCatalogue; use crate::model::requirements::Requires; use crate::model::unterformular::Unterformular; -use crate::model::{Comparable, FolderContent, FormEntryContainer, Listable, Sortable}; +use crate::model::{ + CheckNotice, Checkable, Comparable, FolderContent, FormEntryContainer, Listable, Sortable, +}; use crate::profile::Profile; #[derive(Serialize, Deserialize, Debug)] @@ -409,6 +411,12 @@ impl FromStr for OnkostarEditor { } } +impl Checkable for OnkostarEditor { + fn check(&self) -> Vec { + vec![] + } +} + #[derive(Serialize, Deserialize, Debug)] #[serde(deny_unknown_fields)] pub struct InfoXML {