1
0
mirror of https://github.com/pcvolkmer/osc-variant.git synced 2025-04-20 20:26:50 +00:00

Issue #14: Embed existing DNPM profile files

This commit is contained in:
Paul-Christian Volkmer 2023-11-09 10:47:08 +01:00
parent 4676a63c69
commit 4c76504000
3 changed files with 30 additions and 3 deletions

View File

@ -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. 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` #### 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: 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:

View File

@ -160,9 +160,14 @@ fn main() -> Result<(), Box<dyn Error>> {
let data = &mut read_inputfile(inputfile)?; let data = &mut read_inputfile(inputfile)?;
if let Some(profile) = profile { if let Some(profile) = profile {
let profile = read_profile(profile.clone()).map_err(|_| { let profile = if profile.contains(".") {
read_profile(profile.clone()).map_err(|_| {
FileError::Reading(profile, "Kann Profildatei nicht lesen!".into()) FileError::Reading(profile, "Kann Profildatei nicht lesen!".into())
})?; })?
} else {
Profile::embedded_profile(profile.as_str())?
};
data.apply_profile(&profile); data.apply_profile(&profile);
} }

View File

@ -34,6 +34,19 @@ pub struct Profile {
pub forms: Vec<Form>, 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 { impl FromStr for Profile {
type Err = String; type Err = String;