mirror of
https://github.com/pcvolkmer/osc-variant.git
synced 2025-04-19 11:46:50 +00:00
chore: code cleanup
This commit is contained in:
parent
b4e1113f3d
commit
efa2dc68d6
@ -138,7 +138,7 @@ pub trait Fixable {
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
pub fn check_file(file: &Path, password: Option<String>) -> Result<Vec<CheckNotice>, CheckNotice> {
|
||||
pub fn check_file(file: &Path, password: &Option<String>) -> Result<Vec<CheckNotice>, CheckNotice> {
|
||||
match file.extension() {
|
||||
Some(ex) => match ex.to_str() {
|
||||
#[cfg(feature = "unzip-osb")]
|
||||
@ -163,13 +163,6 @@ pub fn check_file(file: &Path, password: Option<String>) -> Result<Vec<CheckNoti
|
||||
}
|
||||
|
||||
pub fn print_checks() {
|
||||
println!(
|
||||
"{}",
|
||||
style("Die folgenden Probleme sind bekannt\n")
|
||||
.yellow()
|
||||
.bold()
|
||||
);
|
||||
|
||||
struct Problem<'a> {
|
||||
code: &'a str,
|
||||
name: &'a str,
|
||||
@ -184,15 +177,23 @@ pub fn print_checks() {
|
||||
"{} {} {}\n\n{}",
|
||||
style(self.code).bold(),
|
||||
style(self.name).underlined(),
|
||||
match self.fixable {
|
||||
true => style("(Behebbar)").green(),
|
||||
false => style("(Nicht behebbar)").red(),
|
||||
if self.fixable {
|
||||
style("(Behebbar)").green()
|
||||
} else {
|
||||
style("(Nicht behebbar)").red()
|
||||
},
|
||||
self.description
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
println!(
|
||||
"{}",
|
||||
style("Die folgenden Probleme sind bekannt\n")
|
||||
.yellow()
|
||||
.bold()
|
||||
);
|
||||
|
||||
vec![
|
||||
Problem {
|
||||
code: "2023-0001",
|
||||
@ -247,5 +248,5 @@ pub fn print_checks() {
|
||||
},
|
||||
]
|
||||
.iter()
|
||||
.for_each(|problem| println!("{}\n", problem))
|
||||
.for_each(|problem| println!("{problem}\n"));
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ use crate::model::onkostar_editor::OnkostarEditor;
|
||||
|
||||
pub fn check_file(file: &Path) -> Result<Vec<CheckNotice>, CheckNotice> {
|
||||
match fs::read_to_string(file) {
|
||||
Ok(content) => check(content),
|
||||
Ok(content) => check(&content),
|
||||
_ => Err(CheckNotice::Error {
|
||||
description: "Kann Datei nicht lesen".to_string(),
|
||||
line: None,
|
||||
@ -35,18 +35,18 @@ pub fn check_file(file: &Path) -> Result<Vec<CheckNotice>, CheckNotice> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check(content: String) -> Result<Vec<CheckNotice>, CheckNotice> {
|
||||
pub fn check(content: &str) -> Result<Vec<CheckNotice>, CheckNotice> {
|
||||
let mut result = content
|
||||
.lines()
|
||||
.enumerate()
|
||||
.flat_map(|(line, content)| check_line(line, content.to_string()))
|
||||
.flat_map(|(line, content)| check_line(line, content))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let inner_checks = &mut match OnkostarEditor::from_str(content.as_str()) {
|
||||
let inner_checks = &mut match OnkostarEditor::from_str(content) {
|
||||
Ok(data) => data.check(),
|
||||
Err(err) => {
|
||||
return Err(CheckNotice::Error {
|
||||
description: format!("Interner Fehler: {}", err),
|
||||
description: format!("Interner Fehler: {err}"),
|
||||
line: None,
|
||||
})
|
||||
}
|
||||
@ -56,7 +56,7 @@ pub fn check(content: String) -> Result<Vec<CheckNotice>, CheckNotice> {
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn check_line(line: usize, content: String) -> Vec<CheckNotice> {
|
||||
fn check_line(line: usize, content: &str) -> Vec<CheckNotice> {
|
||||
let mut result = vec![];
|
||||
|
||||
if content.contains(" </Bezeichnung>") {
|
||||
@ -67,7 +67,7 @@ fn check_line(line: usize, content: String) -> Vec<CheckNotice> {
|
||||
.to_string(),
|
||||
line: Some(line),
|
||||
example: Some(content.trim().to_string()),
|
||||
}])
|
||||
}]);
|
||||
}
|
||||
|
||||
result
|
||||
|
@ -69,7 +69,7 @@ pub fn handle(command: SubCommand) -> Result<(), Box<dyn Error>> {
|
||||
osc @ InputFile::Osc { .. } => {
|
||||
let mut content: OnkostarEditor = osc.try_into()?;
|
||||
if sorted {
|
||||
content.sorted()
|
||||
content.sorted();
|
||||
}
|
||||
if let Some(name) = filter {
|
||||
OnkostarEditor::print_list_filtered(&mut content, name.as_str());
|
||||
@ -90,20 +90,20 @@ pub fn handle(command: SubCommand) -> Result<(), Box<dyn Error>> {
|
||||
let mut content: OnkostarEditor = match file.try_into() {
|
||||
Ok(oe) => oe,
|
||||
Err(err) => {
|
||||
println!("{}", err);
|
||||
println!("{err}");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
if sorted {
|
||||
content.sorted()
|
||||
content.sorted();
|
||||
}
|
||||
if let Some(name) = filter {
|
||||
OnkostarEditor::print_list_filtered(&mut content, name.as_str());
|
||||
return Ok(());
|
||||
}
|
||||
content.print_list();
|
||||
println!()
|
||||
println!();
|
||||
}
|
||||
_ => {
|
||||
println!(
|
||||
@ -131,7 +131,7 @@ pub fn handle(command: SubCommand) -> Result<(), Box<dyn Error>> {
|
||||
osc @ InputFile::Osc { .. } => {
|
||||
let mut content: OnkostarEditor = osc.try_into()?;
|
||||
if sorted {
|
||||
content.sorted()
|
||||
content.sorted();
|
||||
}
|
||||
if let Some(name) = filter {
|
||||
OnkostarEditor::print_tree_filtered(&mut content, name.as_str());
|
||||
@ -165,9 +165,9 @@ pub fn handle(command: SubCommand) -> Result<(), Box<dyn Error>> {
|
||||
|
||||
if let Some(profile) = profile {
|
||||
let profile = if profile.contains('.') {
|
||||
FileReader::<Profile>::read(profile)?
|
||||
FileReader::<Profile>::read(&profile)?
|
||||
} else {
|
||||
Profile::embedded_profile(profile.as_str())?
|
||||
Profile::embedded_profile(&profile)?
|
||||
};
|
||||
|
||||
data.apply_profile(&profile);
|
||||
@ -243,7 +243,7 @@ pub fn handle(command: SubCommand) -> Result<(), Box<dyn Error>> {
|
||||
match outputfile {
|
||||
Some(filename) => write_outputfile(filename, output)?,
|
||||
None => {
|
||||
println!("{}", output)
|
||||
println!("{output}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -258,8 +258,8 @@ pub fn handle(command: SubCommand) -> Result<(), Box<dyn Error>> {
|
||||
style(&inputfile_b).yellow()
|
||||
);
|
||||
|
||||
let data_a = &mut FileReader::<OnkostarEditor>::read(inputfile_a)?;
|
||||
let data_b = &mut FileReader::<OnkostarEditor>::read(inputfile_b)?;
|
||||
let data_a = &mut FileReader::<OnkostarEditor>::read(&inputfile_a)?;
|
||||
let data_b = &mut FileReader::<OnkostarEditor>::read(&inputfile_b)?;
|
||||
|
||||
data_a.print_diff(data_b, strict);
|
||||
}
|
||||
@ -273,7 +273,7 @@ pub fn handle(command: SubCommand) -> Result<(), Box<dyn Error>> {
|
||||
.unwrap_or_default()
|
||||
.to_str()
|
||||
.unwrap_or_default()
|
||||
)
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("{}", FileError::Reading(inputfile, err.to_string()));
|
||||
@ -287,7 +287,7 @@ pub fn handle(command: SubCommand) -> Result<(), Box<dyn Error>> {
|
||||
if list {
|
||||
print_checks();
|
||||
} else {
|
||||
match check_file(Path::new(file.unwrap_or_default().as_str()), password) {
|
||||
match check_file(Path::new(file.unwrap_or_default().as_str()), &password) {
|
||||
Ok(notices) => {
|
||||
println!(
|
||||
"Es wurden {} Probleme gefunden\n",
|
||||
@ -301,10 +301,10 @@ pub fn handle(command: SubCommand) -> Result<(), Box<dyn Error>> {
|
||||
);
|
||||
notices
|
||||
.iter()
|
||||
.for_each(|check_notice| println!("{}", check_notice));
|
||||
.for_each(|check_notice| println!("{check_notice}"));
|
||||
}
|
||||
Err(err) => {
|
||||
println!("{}", err)
|
||||
println!("{err}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,12 +48,10 @@ impl Display for FileError {
|
||||
f,
|
||||
"{}",
|
||||
match &self {
|
||||
FileError::Reading(filename, err) => format!("Kann Datei '{}' nicht lesen: {}", filename, err),
|
||||
FileError::Writing(filename, err) => format!("Kann Datei '{}' nicht schreiben: {}", filename, err),
|
||||
FileError::Reading(filename, err) => format!("Kann Datei '{filename}' nicht lesen: {err}"),
|
||||
FileError::Writing(filename, err) => format!("Kann Datei '{filename}' nicht schreiben: {err}"),
|
||||
FileError::Parsing(filename, err) => format!(
|
||||
"Die Datei '{}' wird nicht unterstützt, ist fehlerhaft oder enthält zusätzliche Inhalte\n{}",
|
||||
filename,
|
||||
err
|
||||
"Die Datei '{filename}' wird nicht unterstützt, ist fehlerhaft oder enthält zusätzliche Inhalte\n{err}"
|
||||
)
|
||||
}
|
||||
)
|
||||
@ -83,10 +81,10 @@ pub enum InputFile {
|
||||
impl InputFile {
|
||||
pub fn filename(&self) -> String {
|
||||
match self {
|
||||
InputFile::Osc { filename, .. } => filename,
|
||||
InputFile::Osb { filename, .. } => filename,
|
||||
InputFile::Yaml { filename, .. } => filename,
|
||||
InputFile::Other { filename, .. } => filename,
|
||||
InputFile::Osb { filename, .. }
|
||||
| InputFile::Osc { filename, .. }
|
||||
| InputFile::Yaml { filename, .. }
|
||||
| InputFile::Other { filename, .. } => filename,
|
||||
}
|
||||
.to_string()
|
||||
}
|
||||
@ -148,7 +146,7 @@ impl InputFile {
|
||||
content: result,
|
||||
})
|
||||
}
|
||||
Some("yml") | Some("yaml") => match fs::read_to_string(filename.clone()) {
|
||||
Some("yml" | "yaml") => match fs::read_to_string(filename.clone()) {
|
||||
Ok(content) => Ok(InputFile::Yaml { filename, content }),
|
||||
Err(err) => Err(FileError::Reading(filename, err.to_string())),
|
||||
},
|
||||
@ -208,13 +206,13 @@ pub struct FileReader<FileType> {
|
||||
}
|
||||
|
||||
impl FileReader<OnkostarEditor> {
|
||||
pub fn read(filename: String) -> Result<OnkostarEditor, FileError> {
|
||||
pub fn read(filename: &str) -> Result<OnkostarEditor, FileError> {
|
||||
TryInto::<OnkostarEditor>::try_into(InputFile::read(filename.to_string(), None)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl FileReader<Profile> {
|
||||
pub fn read(filename: String) -> Result<Profile, FileError> {
|
||||
pub fn read(filename: &str) -> Result<Profile, FileError> {
|
||||
TryInto::<Profile>::try_into(InputFile::read(filename.to_string(), None)?)
|
||||
}
|
||||
}
|
||||
|
@ -63,9 +63,10 @@ impl Listable for DataCatalogue {
|
||||
fn to_listed_string(&self) -> String {
|
||||
format!(
|
||||
"Datenkatalog ({}) '{}' in Revision '{}'",
|
||||
match self.is_system_library_content() {
|
||||
true => style("S").yellow(),
|
||||
_ => style("u"),
|
||||
if self.is_system_library_content() {
|
||||
style("S").yellow()
|
||||
} else {
|
||||
style("u")
|
||||
},
|
||||
style(&self.name).yellow(),
|
||||
style(&self.revision).yellow()
|
||||
@ -129,11 +130,9 @@ impl Requires for DataCatalogue {
|
||||
self.get_required_entries(all)
|
||||
.iter()
|
||||
.map(|entry| match entry {
|
||||
Requirement::PropertyCatalogue(_) => {
|
||||
Some(format!(" - {}\n", entry))
|
||||
}
|
||||
Requirement::ExternalPropertyCatalogue(_) => {
|
||||
Some(format!(" - {}\n", entry))
|
||||
Requirement::PropertyCatalogue(_)
|
||||
| Requirement::ExternalPropertyCatalogue(_) => {
|
||||
Some(format!(" - {entry}\n"))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
@ -231,7 +230,7 @@ impl Sortable for Entry {
|
||||
{
|
||||
if let Some(ref mut use_) = self.use_ {
|
||||
use_.program_module
|
||||
.sort_unstable_by_key(|item| item.sorting_key())
|
||||
.sort_unstable_by_key(|item| item.sorting_key());
|
||||
}
|
||||
self
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ impl<Type: 'static> FormEntryContainer for Form<Type> {
|
||||
.form_references
|
||||
.iter()
|
||||
.for_each(|form_reference| {
|
||||
apply_profile_to_form_entry(entry, form_reference)
|
||||
apply_profile_to_form_entry(entry, form_reference);
|
||||
});
|
||||
|
||||
// Hide form field using filter set to "false" if requested and change default value
|
||||
@ -226,7 +226,7 @@ impl<Type: 'static> FormEntryContainer for Form<Type> {
|
||||
column: menu_category.column.clone(),
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -241,9 +241,10 @@ impl<Type: 'static> Listable for Form<Type> {
|
||||
} else {
|
||||
"Unterformular"
|
||||
},
|
||||
match self.is_system_library_content() {
|
||||
true => style("S").yellow(),
|
||||
_ => style("u"),
|
||||
if self.is_system_library_content() {
|
||||
style("S").yellow()
|
||||
} else {
|
||||
style("u")
|
||||
},
|
||||
style(&self.name).yellow(),
|
||||
style(&self.revision).yellow()
|
||||
|
@ -323,7 +323,7 @@ where
|
||||
entry.update_scripts_code(scripts_code.clone());
|
||||
}
|
||||
if form_reference.remove_filter {
|
||||
entry.remove_filter()
|
||||
entry.remove_filter();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -334,16 +334,16 @@ where
|
||||
{
|
||||
if entry.get_name() == form_field.name {
|
||||
if form_field.hide {
|
||||
entry.hide()
|
||||
entry.hide();
|
||||
}
|
||||
if let Some(new_default_value) = &form_field.default_value {
|
||||
entry.update_default_value(new_default_value.to_string())
|
||||
entry.update_default_value(new_default_value.to_string());
|
||||
}
|
||||
if let Some(scripts_code) = &form_field.escaped_scripts_code() {
|
||||
entry.update_scripts_code(scripts_code.clone());
|
||||
}
|
||||
if form_field.remove_filter {
|
||||
entry.remove_filter()
|
||||
entry.remove_filter();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -372,7 +372,7 @@ pub trait Comparable: Debug {
|
||||
fn get_revision(&self) -> u16;
|
||||
fn get_hash(&self) -> String {
|
||||
let mut h = DefaultHasher::new();
|
||||
format!("{:?}", self).hash(&mut h);
|
||||
format!("{self:?}").hash(&mut h);
|
||||
h.finish().to_string()
|
||||
}
|
||||
fn compare_by_requirement(_: &Self, _: &Self) -> Ordering
|
||||
|
@ -381,7 +381,7 @@ impl OnkostarEditor {
|
||||
);
|
||||
has_diff = true;
|
||||
} else if strict {
|
||||
println!("{}: {}", entry_a.get_name(), style("Identisch").green())
|
||||
println!("{}: {}", entry_a.get_name(), style("Identisch").green());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -390,7 +390,7 @@ impl OnkostarEditor {
|
||||
});
|
||||
|
||||
if !has_diff {
|
||||
println!("Keine Unterschiede")
|
||||
println!("Keine Unterschiede");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -464,12 +464,12 @@ impl Checkable for OnkostarEditor {
|
||||
.for_each(|entry| match entry {
|
||||
Requirement::DataFormReference(item) => {
|
||||
if !requirement_checked_forms.contains(&item.get_name()) {
|
||||
result.push(requirement_error(form, *item, "Formular"))
|
||||
result.push(requirement_error(form, *item, "Formular"));
|
||||
}
|
||||
}
|
||||
Requirement::UnterformularReference(item) => {
|
||||
if !requirement_checked_forms.contains(&item.get_name()) {
|
||||
result.push(requirement_error(form, *item, "Unterformular"))
|
||||
result.push(requirement_error(form, *item, "Unterformular"));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
@ -483,12 +483,12 @@ impl Checkable for OnkostarEditor {
|
||||
.for_each(|entry| match entry {
|
||||
Requirement::DataFormReference(item) => {
|
||||
if !requirement_checked_forms.contains(&item.get_name()) {
|
||||
result.push(requirement_error(form, *item, "Formular"))
|
||||
result.push(requirement_error(form, *item, "Formular"));
|
||||
}
|
||||
}
|
||||
Requirement::UnterformularReference(item) => {
|
||||
if !requirement_checked_forms.contains(&item.get_name()) {
|
||||
result.push(requirement_error(form, *item, "Unterformular"))
|
||||
result.push(requirement_error(form, *item, "Unterformular"));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
@ -528,7 +528,7 @@ impl FormEntry for Entry {
|
||||
}
|
||||
|
||||
fn update_default_value(&mut self, value: String) {
|
||||
self.default_value = value
|
||||
self.default_value = value;
|
||||
}
|
||||
|
||||
fn hide(&mut self) {
|
||||
@ -537,7 +537,7 @@ impl FormEntry for Entry {
|
||||
valid: true,
|
||||
ref_entries: Some(RefEntries { ref_entry: None }),
|
||||
});
|
||||
self.speichern = "0".into()
|
||||
self.speichern = "0".into();
|
||||
}
|
||||
|
||||
fn remove_filter(&mut self) {
|
||||
@ -557,7 +557,7 @@ impl Sortable for Entry {
|
||||
if let Some(ref mut filter) = self.filter {
|
||||
if let Some(ref mut ref_entries) = filter.ref_entries {
|
||||
if let Some(ref mut ref_entry) = ref_entries.ref_entry {
|
||||
ref_entry.sort_unstable()
|
||||
ref_entry.sort_unstable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,21 +73,21 @@ impl Display for Requirement<'_> {
|
||||
Requirement::DataFormSubform(item) => item.to_listed_string(),
|
||||
Requirement::UnterformularSubform(item) => item.to_listed_string(),
|
||||
Requirement::ExternalPropertyCatalogue(name) => {
|
||||
format!("Merkmalskatalog (-) '{}' - hier nicht enthalten", name)
|
||||
format!("Merkmalskatalog (-) '{name}' - hier nicht enthalten")
|
||||
}
|
||||
Requirement::ExternalDataCatalogue(name) => {
|
||||
format!("Datenkatalog (-) '{}' - hier nicht enthalten", name)
|
||||
format!("Datenkatalog (-) '{name}' - hier nicht enthalten")
|
||||
}
|
||||
Requirement::ExternalDataFormReference(name)
|
||||
| Requirement::ExternalDataFormSubform(name) => {
|
||||
format!("Formular (-) '{}' - hier nicht enthalten", name)
|
||||
format!("Formular (-) '{name}' - hier nicht enthalten")
|
||||
}
|
||||
Requirement::ExternalUnterformularReference(name)
|
||||
| Requirement::ExternalUnterformularSubform(name) => {
|
||||
format!("Unterformular (-) '{}' - hier nicht enthalten", name)
|
||||
format!("Unterformular (-) '{name}' - hier nicht enthalten")
|
||||
}
|
||||
};
|
||||
write!(f, "{}", str)
|
||||
write!(f, "{str}")
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,19 +134,19 @@ where
|
||||
}
|
||||
}
|
||||
Requirement::ExternalDataCatalogue(_) => {
|
||||
Some(format!(" + {}\n", entry))
|
||||
Some(format!(" + {entry}\n"))
|
||||
}
|
||||
Requirement::DataFormReference(_)
|
||||
| Requirement::ExternalDataFormReference(_)
|
||||
| Requirement::UnterformularReference(_)
|
||||
| Requirement::ExternalUnterformularReference(_) => {
|
||||
Some(format!(" > {}\n", entry))
|
||||
Some(format!(" > {entry}\n"))
|
||||
}
|
||||
Requirement::DataFormSubform(_)
|
||||
| Requirement::ExternalDataFormSubform(_)
|
||||
| Requirement::UnterformularSubform(_)
|
||||
| Requirement::ExternalUnterformularSubform(_) => {
|
||||
Some(format!(" * {}\n", entry))
|
||||
Some(format!(" * {entry}\n"))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user