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::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<CheckNotice> {
|
||||
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::<Vec<_>>(),
|
||||
_ => {
|
||||
return vec![CheckNotice::Error {
|
||||
pub fn check_file(file: &Path) -> Vec<CheckNotice> {
|
||||
match fs::read_to_string(file) {
|
||||
Ok(content) => check(content),
|
||||
_ => 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()) {
|
||||
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,
|
||||
}],
|
||||
},
|
||||
_ => vec![CheckNotice::Error {
|
||||
description: "Kann Datei nicht lesen".to_string(),
|
||||
line: None,
|
||||
}],
|
||||
};
|
||||
result.append(inner_checks);
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user