mirror of
https://github.com/pcvolkmer/osc-variant.git
synced 2025-04-19 19:56:50 +00:00
Add optional sorted listing of file contents
This commit is contained in:
parent
0f584997f7
commit
11b233b642
@ -39,6 +39,10 @@ Ohne eine Angabe der Ausgabedatei wird auf die Standardausgabe ausgegeben.
|
|||||||
OSC-Dateien sind XML-Dateien. Diese Anwendung ermöglicht optional die Ausgabe als kompaktere XML-Datei ohne Zeilenumbrüche.
|
OSC-Dateien sind XML-Dateien. Diese Anwendung ermöglicht optional die Ausgabe als kompaktere XML-Datei ohne Zeilenumbrüche.
|
||||||
Hierzu ist die Option `--compact` vorgesehen. Es können, je nach Datei, bis zu 30% eingespart werden.
|
Hierzu ist die Option `--compact` vorgesehen. Es können, je nach Datei, bis zu 30% eingespart werden.
|
||||||
|
|
||||||
|
#### Sortierung
|
||||||
|
|
||||||
|
Bei der Auflistung der Inhalte, kann optional `--sorted` dazu verwendet werden, die angezeigten Einträge alphabetisch zu sortieren.
|
||||||
|
|
||||||
## Profile
|
## Profile
|
||||||
|
|
||||||
Zum Erstellen von Varianten einer OSC-Datei wird eine Profildatei im YAML-Format verwendet.
|
Zum Erstellen von Varianten einer OSC-Datei wird eine Profildatei im YAML-Format verwendet.
|
||||||
|
@ -35,7 +35,14 @@ pub struct Cli {
|
|||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
#[command(about = "Zeigt alle enthaltenen Kataloge und Formulare mit Revision an.")]
|
#[command(about = "Zeigt alle enthaltenen Kataloge und Formulare mit Revision an.")]
|
||||||
List { inputfile: String },
|
List {
|
||||||
|
inputfile: String,
|
||||||
|
#[arg(
|
||||||
|
long = "sorted",
|
||||||
|
help = "Sortiere Kataloge und Formulare nach Name (Optional)"
|
||||||
|
)]
|
||||||
|
sorted: bool,
|
||||||
|
},
|
||||||
#[command(about = "Modifiziert die angegebene Datei anhand der Profildatei")]
|
#[command(about = "Modifiziert die angegebene Datei anhand der Profildatei")]
|
||||||
Modify {
|
Modify {
|
||||||
inputfile: String,
|
inputfile: String,
|
||||||
|
@ -109,8 +109,11 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
match cli.command {
|
match cli.command {
|
||||||
Command::List { inputfile } => {
|
Command::List { inputfile, sorted } => {
|
||||||
let data = read_inputfile(inputfile)?;
|
let mut data = read_inputfile(inputfile)?;
|
||||||
|
if sorted {
|
||||||
|
data.sorted()
|
||||||
|
}
|
||||||
data.print_list();
|
data.print_list();
|
||||||
}
|
}
|
||||||
Command::Modify {
|
Command::Modify {
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::model::{Listable, Ordner};
|
use crate::model::{Listable, Ordner, Sortable};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
@ -64,6 +64,12 @@ impl Listable for DataCatalogue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Sortable for DataCatalogue {
|
||||||
|
fn sorting_key(&self) -> String {
|
||||||
|
self.name.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct Entries {
|
pub struct Entries {
|
||||||
|
@ -26,7 +26,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use crate::model::{
|
use crate::model::{
|
||||||
apply_profile_to_form_entry, Ansichten, Entries, Filter, FormEntry, FormEntryContainer,
|
apply_profile_to_form_entry, Ansichten, Entries, Filter, FormEntry, FormEntryContainer,
|
||||||
Listable, MenuCategory, PlausibilityRules, Script,
|
Listable, MenuCategory, PlausibilityRules, Script, Sortable,
|
||||||
};
|
};
|
||||||
use crate::model::{Haeufigkeiten, Ordner};
|
use crate::model::{Haeufigkeiten, Ordner};
|
||||||
use crate::profile::Profile;
|
use crate::profile::Profile;
|
||||||
@ -183,6 +183,12 @@ impl Listable for DataForm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Sortable for DataForm {
|
||||||
|
fn sorting_key(&self) -> String {
|
||||||
|
self.name.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct DataCatalogues {
|
pub struct DataCatalogues {
|
||||||
|
@ -234,6 +234,10 @@ pub trait Listable {
|
|||||||
fn to_listed_string(&self) -> String;
|
fn to_listed_string(&self) -> String;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait Sortable {
|
||||||
|
fn sorting_key(&self) -> String;
|
||||||
|
}
|
||||||
|
|
||||||
pub trait FormEntry {
|
pub trait FormEntry {
|
||||||
fn get_name(&self) -> String;
|
fn get_name(&self) -> String;
|
||||||
fn get_type(&self) -> String;
|
fn get_type(&self) -> String;
|
||||||
|
@ -31,7 +31,7 @@ use crate::model::data_catalogue::DataCatalogue;
|
|||||||
use crate::model::data_form::DataForm;
|
use crate::model::data_form::DataForm;
|
||||||
use crate::model::property_catalogue::PropertyCatalogue;
|
use crate::model::property_catalogue::PropertyCatalogue;
|
||||||
use crate::model::unterformular::Unterformular;
|
use crate::model::unterformular::Unterformular;
|
||||||
use crate::model::{FormEntryContainer, Listable};
|
use crate::model::{FormEntryContainer, Listable, Sortable};
|
||||||
use crate::profile::Profile;
|
use crate::profile::Profile;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
@ -71,6 +71,24 @@ impl OnkostarEditor {
|
|||||||
list.iter()
|
list.iter()
|
||||||
.for_each(|entry| println!("{}", entry.to_listed_string()));
|
.for_each(|entry| println!("{}", entry.to_listed_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn sorted(&mut self) {
|
||||||
|
self.editor
|
||||||
|
.property_catalogue
|
||||||
|
.sort_unstable_by_key(|e| e.sorting_key());
|
||||||
|
|
||||||
|
self.editor
|
||||||
|
.data_catalogue
|
||||||
|
.sort_unstable_by_key(|e| e.sorting_key());
|
||||||
|
|
||||||
|
self.editor
|
||||||
|
.data_form
|
||||||
|
.sort_unstable_by_key(|e| e.sorting_key());
|
||||||
|
|
||||||
|
self.editor
|
||||||
|
.unterformular
|
||||||
|
.sort_unstable_by_key(|e| e.sorting_key());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for OnkostarEditor {
|
impl FromStr for OnkostarEditor {
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::model::{Listable, Ordner};
|
use crate::model::{Listable, Ordner, Sortable};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
@ -61,6 +61,12 @@ impl Listable for PropertyCatalogue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Sortable for PropertyCatalogue {
|
||||||
|
fn sorting_key(&self) -> String {
|
||||||
|
self.name.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct Versions {
|
pub struct Versions {
|
||||||
|
@ -27,7 +27,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use crate::model::{
|
use crate::model::{
|
||||||
apply_profile_to_form_entry, Ansichten, Entries, Filter, FormEntry, FormEntryContainer,
|
apply_profile_to_form_entry, Ansichten, Entries, Filter, FormEntry, FormEntryContainer,
|
||||||
Listable, MenuCategory, PlausibilityRules, Script,
|
Listable, MenuCategory, PlausibilityRules, Script, Sortable,
|
||||||
};
|
};
|
||||||
use crate::model::{Haeufigkeiten, Ordner};
|
use crate::model::{Haeufigkeiten, Ordner};
|
||||||
use crate::profile::Profile;
|
use crate::profile::Profile;
|
||||||
@ -206,6 +206,12 @@ impl Listable for Unterformular {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Sortable for Unterformular {
|
||||||
|
fn sorting_key(&self) -> String {
|
||||||
|
self.name.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct DataCatalogues {
|
pub struct DataCatalogues {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user