mirror of
https://github.com/pcvolkmer/osc-variant.git
synced 2025-07-03 01:02:55 +00:00
Issue #14: Embed existing DNPM profile files
This commit is contained in:
11
src/main.rs
11
src/main.rs
@ -160,9 +160,14 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
let data = &mut read_inputfile(inputfile)?;
|
||||
|
||||
if let Some(profile) = profile {
|
||||
let profile = read_profile(profile.clone()).map_err(|_| {
|
||||
FileError::Reading(profile, "Kann Profildatei nicht lesen!".into())
|
||||
})?;
|
||||
let profile = if profile.contains(".") {
|
||||
read_profile(profile.clone()).map_err(|_| {
|
||||
FileError::Reading(profile, "Kann Profildatei nicht lesen!".into())
|
||||
})?
|
||||
} else {
|
||||
Profile::embedded_profile(profile.as_str())?
|
||||
};
|
||||
|
||||
data.apply_profile(&profile);
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,19 @@ pub struct Profile {
|
||||
pub forms: Vec<Form>,
|
||||
}
|
||||
|
||||
impl Profile {
|
||||
pub fn embedded_profile(name: &str) -> Result<Profile, String> {
|
||||
let s = match name {
|
||||
"UKM" => include_str!("../examples/dnpm-ukm.yml"),
|
||||
"UKW" => include_str!("../examples/dnpm-ukw.yml"),
|
||||
"UMG" => include_str!("../examples/dnpm-umg.yml"),
|
||||
_ => return Err(format!("Not an embedded profile: '{name}'")),
|
||||
};
|
||||
|
||||
Profile::from_str(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Profile {
|
||||
type Err = String;
|
||||
|
||||
|
Reference in New Issue
Block a user