diff --git a/src/checks/osc.rs b/src/checks/osc.rs index 86ca634..2140906 100644 --- a/src/checks/osc.rs +++ b/src/checks/osc.rs @@ -25,46 +25,32 @@ use crate::checks::{CheckNotice, Checkable}; use crate::model::onkostar_editor::OnkostarEditor; use std::fs; -use std::fs::File; -use std::io::{BufRead, BufReader}; use std::path::Path; use std::str::FromStr; -pub fn check(file: &Path) -> Vec { - let mut result = match File::open(file) { - Ok(file) => BufReader::new(file) - .lines() - .enumerate() - .flat_map(|(line, content)| match content { - Ok(content) => check_line(line, content), - _ => { - return vec![CheckNotice::Error { - description: "Cannot read line".to_string(), - line: Some(line), - }] - } - }) - .collect::>(), - _ => { - return vec![CheckNotice::Error { - description: "Kann Datei nicht lesen".to_string(), - line: None, - }] - } - }; - - let inner_checks = &mut match fs::read_to_string(file) { - Ok(content) => match OnkostarEditor::from_str(content.as_str()) { - Ok(data) => data.check(), - Err(err) => vec![CheckNotice::Error { - description: format!("Interner Fehler: {}", err), - line: None, - }], - }, +pub fn check_file(file: &Path) -> Vec { + match fs::read_to_string(file) { + Ok(content) => check(content), _ => vec![CheckNotice::Error { description: "Kann Datei nicht lesen".to_string(), line: None, }], + } +} + +pub fn check(content: String) -> Vec { + let mut result = content + .lines() + .enumerate() + .flat_map(|(line, content)| check_line(line, content.to_string())) + .collect::>(); + + let inner_checks = &mut match OnkostarEditor::from_str(content.as_str()) { + Ok(data) => data.check(), + Err(err) => vec![CheckNotice::Error { + description: format!("Interner Fehler: {}", err), + line: None, + }], }; result.append(inner_checks); diff --git a/src/main.rs b/src/main.rs index 217cbe8..33502d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,7 +32,7 @@ use std::path::{Path, PathBuf}; use std::str::FromStr; use crate::checks::osc::check; -use crate::checks::{print_checks, CheckNotice}; +use crate::checks::print_checks; use clap::Parser; use console::style; use dialoguer::Confirm;