mirror of
https://github.com/pcvolkmer/bzkf-rwdp-check.git
synced 2025-04-19 19:16:51 +00:00
feat: use PathBuf as argument type
This commit is contained in:
parent
af44351f09
commit
9f5188ce5d
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(author, version, about)]
|
#[command(author, version, about)]
|
||||||
@ -34,7 +35,7 @@ pub enum SubCommand {
|
|||||||
#[command(about = "Ermittelt die Prüfwerte aus einem CSV-File für OPAL")]
|
#[command(about = "Ermittelt die Prüfwerte aus einem CSV-File für OPAL")]
|
||||||
OpalFile {
|
OpalFile {
|
||||||
#[arg(short, long, help = "CSV-File für Opal")]
|
#[arg(short, long, help = "CSV-File für Opal")]
|
||||||
file: String,
|
file: PathBuf,
|
||||||
},
|
},
|
||||||
#[command(about = "Ermittelt die Prüfwerte aus der Onkostar-Datenbank")]
|
#[command(about = "Ermittelt die Prüfwerte aus der Onkostar-Datenbank")]
|
||||||
Database {
|
Database {
|
||||||
@ -95,7 +96,7 @@ pub enum SubCommand {
|
|||||||
#[arg(short = 'u', long, help = "Benutzername")]
|
#[arg(short = 'u', long, help = "Benutzername")]
|
||||||
user: String,
|
user: String,
|
||||||
#[arg(short = 'o', long, help = "Ausgabedatei")]
|
#[arg(short = 'o', long, help = "Ausgabedatei")]
|
||||||
output: String,
|
output: PathBuf,
|
||||||
#[arg(short = 'y', long, help = "Jahr der Diagnose")]
|
#[arg(short = 'y', long, help = "Jahr der Diagnose")]
|
||||||
year: String,
|
year: String,
|
||||||
#[arg(long, value_parser = value_is_date, help = "Ignoriere LKR-Exporte seit Datum")]
|
#[arg(long, value_parser = value_is_date, help = "Ignoriere LKR-Exporte seit Datum")]
|
||||||
@ -134,7 +135,7 @@ pub enum SubCommand {
|
|||||||
#[arg(short = 'u', long, help = "Benutzername")]
|
#[arg(short = 'u', long, help = "Benutzername")]
|
||||||
user: String,
|
user: String,
|
||||||
#[arg(short, long, help = "CSV-File für Opal")]
|
#[arg(short, long, help = "CSV-File für Opal")]
|
||||||
file: String,
|
file: PathBuf,
|
||||||
#[arg(short = 'y', long, help = "Jahr der Diagnose")]
|
#[arg(short = 'y', long, help = "Jahr der Diagnose")]
|
||||||
year: String,
|
year: String,
|
||||||
#[arg(long, value_parser = value_is_date, help = "Ignoriere LKR-Exporte seit Datum")]
|
#[arg(long, value_parser = value_is_date, help = "Ignoriere LKR-Exporte seit Datum")]
|
||||||
|
17
src/main.rs
17
src/main.rs
@ -19,7 +19,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use console::{style, Term};
|
use console::{style, Term};
|
||||||
@ -106,8 +105,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
match Cli::parse().cmd {
|
match Cli::parse().cmd {
|
||||||
SubCommand::OpalFile { file } => {
|
SubCommand::OpalFile { file } => {
|
||||||
let items = opal::OpalCsvFile::check(Path::new(&file))
|
let items =
|
||||||
.map_err(|_e| "Kann Datei nicht lesen")?;
|
opal::OpalCsvFile::check(file.as_path()).map_err(|_e| "Kann Datei nicht lesen")?;
|
||||||
|
|
||||||
print_items(&items);
|
print_items(&items);
|
||||||
}
|
}
|
||||||
@ -188,7 +187,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
writer_builder = writer_builder.delimiter(b';');
|
writer_builder = writer_builder.delimiter(b';');
|
||||||
}
|
}
|
||||||
let mut writer = writer_builder
|
let mut writer = writer_builder
|
||||||
.from_path(Path::new(&output))
|
.from_path(output.as_path())
|
||||||
.expect("writeable file");
|
.expect("writeable file");
|
||||||
|
|
||||||
items
|
items
|
||||||
@ -200,7 +199,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
"{} Conditions für das Jahr {} in Datei '{}' exportiert",
|
"{} Conditions für das Jahr {} in Datei '{}' exportiert",
|
||||||
items.len(),
|
items.len(),
|
||||||
year,
|
year,
|
||||||
output
|
output.to_str().unwrap_or_default()
|
||||||
))
|
))
|
||||||
.green()
|
.green()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
@ -243,8 +242,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
let _ = term.clear_last_lines(1);
|
let _ = term.clear_last_lines(1);
|
||||||
|
|
||||||
let csv_items = opal::OpalCsvFile::export(Path::new(&file))
|
let csv_items =
|
||||||
.map_err(|_e| "Kann Datei nicht lesen")?;
|
opal::OpalCsvFile::export(file.as_path()).map_err(|_e| "Kann Datei nicht lesen")?;
|
||||||
|
|
||||||
let mut not_in_csv = db_items
|
let mut not_in_csv = db_items
|
||||||
.iter()
|
.iter()
|
||||||
@ -263,7 +262,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
"{} Conditions aus der Datenbank für das Jahr {} - aber nicht in Datei '{}'",
|
"{} Conditions aus der Datenbank für das Jahr {} - aber nicht in Datei '{}'",
|
||||||
not_in_csv.len(),
|
not_in_csv.len(),
|
||||||
year,
|
year,
|
||||||
file
|
file.to_str().unwrap_or_default()
|
||||||
))
|
))
|
||||||
.green()
|
.green()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
@ -321,7 +320,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
&style(format!(
|
&style(format!(
|
||||||
"{} Conditions aus Datei '{}' - aber nicht in der Datenbank für das Jahr {}",
|
"{} Conditions aus Datei '{}' - aber nicht in der Datenbank für das Jahr {}",
|
||||||
not_in_db.len(),
|
not_in_db.len(),
|
||||||
file,
|
file.to_str().unwrap_or_default(),
|
||||||
year
|
year
|
||||||
))
|
))
|
||||||
.green()
|
.green()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user