1
0
mirror of https://github.com/pcvolkmer/osc-variant.git synced 2025-04-19 19:56:50 +00:00

Issue #15: Implement check subcommand cli

This commit is contained in:
Paul-Christian Volkmer 2023-11-06 09:37:03 +01:00
parent dce2a5cdda
commit a55db66e57
4 changed files with 41 additions and 2 deletions

View File

@ -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 {

View File

@ -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<dyn Error>> {
}
};
}
SubCommand::Check { file } => {
read_inputfile(file)?
.check()
.iter()
.for_each(|check_notice| println!("{}", check_notice));
}
#[cfg(feature = "unzip-osb")]
SubCommand::UnzipOsb {
file,

View File

@ -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<CheckNotice>;
}

View File

@ -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<CheckNotice> {
vec![]
}
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct InfoXML {