mirror of
https://github.com/pcvolkmer/osc-variant.git
synced 2025-04-19 19:56:50 +00:00
Issue #19: Extract method to check content of OSC file
This commit is contained in:
parent
7ab5523f3c
commit
d45ded939e
@ -25,46 +25,32 @@
|
|||||||
use crate::checks::{CheckNotice, Checkable};
|
use crate::checks::{CheckNotice, Checkable};
|
||||||
use crate::model::onkostar_editor::OnkostarEditor;
|
use crate::model::onkostar_editor::OnkostarEditor;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::File;
|
|
||||||
use std::io::{BufRead, BufReader};
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
pub fn check(file: &Path) -> Vec<CheckNotice> {
|
pub fn check_file(file: &Path) -> Vec<CheckNotice> {
|
||||||
let mut result = match File::open(file) {
|
match fs::read_to_string(file) {
|
||||||
Ok(file) => BufReader::new(file)
|
Ok(content) => check(content),
|
||||||
.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::<Vec<_>>(),
|
|
||||||
_ => {
|
|
||||||
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,
|
|
||||||
}],
|
|
||||||
},
|
|
||||||
_ => vec![CheckNotice::Error {
|
_ => vec![CheckNotice::Error {
|
||||||
description: "Kann Datei nicht lesen".to_string(),
|
description: "Kann Datei nicht lesen".to_string(),
|
||||||
line: None,
|
line: None,
|
||||||
}],
|
}],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn check(content: String) -> Vec<CheckNotice> {
|
||||||
|
let mut result = content
|
||||||
|
.lines()
|
||||||
|
.enumerate()
|
||||||
|
.flat_map(|(line, content)| check_line(line, content.to_string()))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
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);
|
result.append(inner_checks);
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ use std::path::{Path, PathBuf};
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use crate::checks::osc::check;
|
use crate::checks::osc::check;
|
||||||
use crate::checks::{print_checks, CheckNotice};
|
use crate::checks::print_checks;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use console::style;
|
use console::style;
|
||||||
use dialoguer::Confirm;
|
use dialoguer::Confirm;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user