mirror of
https://github.com/pcvolkmer/osc-variant.git
synced 2025-04-19 19:56:50 +00:00
feat: add shortcut methods to read OSC and Profile files
This commit is contained in:
parent
dc62454a74
commit
221b2c6a2f
@ -37,7 +37,7 @@ use sha256::digest;
|
|||||||
|
|
||||||
use crate::checks::{check_file, print_checks, CheckNotice};
|
use crate::checks::{check_file, print_checks, CheckNotice};
|
||||||
use crate::cli::SubCommand;
|
use crate::cli::SubCommand;
|
||||||
use crate::file_io::{FileError, InputFile};
|
use crate::file_io::{FileError, FileReader, InputFile};
|
||||||
use crate::model::onkostar_editor::OnkostarEditor;
|
use crate::model::onkostar_editor::OnkostarEditor;
|
||||||
use crate::profile::Profile;
|
use crate::profile::Profile;
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ pub fn handle(command: SubCommand) -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
if let Some(profile) = profile {
|
if let Some(profile) = profile {
|
||||||
let profile = if profile.contains('.') {
|
let profile = if profile.contains('.') {
|
||||||
InputFile::read(profile.to_string(), None)?.try_into()?
|
FileReader::<Profile>::read(profile)?
|
||||||
} else {
|
} else {
|
||||||
Profile::embedded_profile(profile.as_str())?
|
Profile::embedded_profile(profile.as_str())?
|
||||||
};
|
};
|
||||||
@ -243,10 +243,8 @@ pub fn handle(command: SubCommand) -> Result<(), Box<dyn Error>> {
|
|||||||
style(&inputfile_b).yellow()
|
style(&inputfile_b).yellow()
|
||||||
);
|
);
|
||||||
|
|
||||||
let data_a: &mut OnkostarEditor =
|
let data_a = &mut FileReader::<OnkostarEditor>::read(inputfile_a)?;
|
||||||
&mut InputFile::read(inputfile_a, None)?.try_into()?;
|
let data_b = &mut FileReader::<OnkostarEditor>::read(inputfile_b)?;
|
||||||
let data_b: &mut OnkostarEditor =
|
|
||||||
&mut InputFile::read(inputfile_b, None)?.try_into()?;
|
|
||||||
|
|
||||||
data_a.print_diff(data_b, strict);
|
data_a.print_diff(data_b, strict);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt::{Debug, Display, Formatter};
|
use std::fmt::{Debug, Display, Formatter};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::marker::PhantomData;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
@ -206,3 +207,20 @@ impl TryFrom<InputFile> for Profile {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Shortcut methods for OSC and Profile files
|
||||||
|
pub struct FileReader<FileType> {
|
||||||
|
file_type: PhantomData<FileType>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FileReader<OnkostarEditor> {
|
||||||
|
pub fn read(filename: String) -> Result<OnkostarEditor, FileError> {
|
||||||
|
TryInto::<OnkostarEditor>::try_into(InputFile::read(filename.to_string(), None)?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FileReader<Profile> {
|
||||||
|
pub fn read(filename: String) -> Result<Profile, FileError> {
|
||||||
|
TryInto::<Profile>::try_into(InputFile::read(filename.to_string(), None)?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user