From 4c765040002c17aa9fb1b2f466611d31d95e33fc Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Thu, 9 Nov 2023 10:47:08 +0100 Subject: [PATCH] Issue #14: Embed existing DNPM profile files --- README.md | 9 +++++++++ src/main.rs | 11 ++++++++--- src/profile.rs | 13 +++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1720d6f..1c87eb5 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,15 @@ Ohne Profildatei wird die Datei lediglich eingelesen, Leerzeichen am Ende eines Ohne eine Angabe der Ausgabedatei wird auf die Standardausgabe ausgegeben. +##### Enthaltene Profile + +Die im Ordner [`examples/`](/examples) enthaltenen Profile für Standorte sind in der ausführbaren Anwendung enthalten +und die Dateien müssen nicht explizit als Datei vorliegen: + +* `--profile examples/dnpm-ukm.yml` => `--profile UKM` +* `--profile examples/dnpm-ukw.yml` => `--profile UKW` +* `--profile examples/dnpm-umg.yml` => `--profile UMG` + #### Unterbefehl `unzip-osb` Ab Version 0.6.0 ist die Anwendung zudem in der Lage, die für eine Aktualisierung der OS-Bibliothek genutzten OSB-Dateien zu entpacken: diff --git a/src/main.rs b/src/main.rs index 5b2d54b..90de1fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -160,9 +160,14 @@ fn main() -> Result<(), Box> { 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); } diff --git a/src/profile.rs b/src/profile.rs index 8171331..41af8f1 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -34,6 +34,19 @@ pub struct Profile { pub forms: Vec
, } +impl Profile { + pub fn embedded_profile(name: &str) -> Result { + 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;