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 regex::Regex;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about)]
|
||||
@ -34,7 +35,7 @@ pub enum SubCommand {
|
||||
#[command(about = "Ermittelt die Prüfwerte aus einem CSV-File für OPAL")]
|
||||
OpalFile {
|
||||
#[arg(short, long, help = "CSV-File für Opal")]
|
||||
file: String,
|
||||
file: PathBuf,
|
||||
},
|
||||
#[command(about = "Ermittelt die Prüfwerte aus der Onkostar-Datenbank")]
|
||||
Database {
|
||||
@ -95,7 +96,7 @@ pub enum SubCommand {
|
||||
#[arg(short = 'u', long, help = "Benutzername")]
|
||||
user: String,
|
||||
#[arg(short = 'o', long, help = "Ausgabedatei")]
|
||||
output: String,
|
||||
output: PathBuf,
|
||||
#[arg(short = 'y', long, help = "Jahr der Diagnose")]
|
||||
year: String,
|
||||
#[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")]
|
||||
user: String,
|
||||
#[arg(short, long, help = "CSV-File für Opal")]
|
||||
file: String,
|
||||
file: PathBuf,
|
||||
#[arg(short = 'y', long, help = "Jahr der Diagnose")]
|
||||
year: String,
|
||||
#[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::path::Path;
|
||||
|
||||
use clap::Parser;
|
||||
use console::{style, Term};
|
||||
@ -106,8 +105,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
match Cli::parse().cmd {
|
||||
SubCommand::OpalFile { file } => {
|
||||
let items = opal::OpalCsvFile::check(Path::new(&file))
|
||||
.map_err(|_e| "Kann Datei nicht lesen")?;
|
||||
let items =
|
||||
opal::OpalCsvFile::check(file.as_path()).map_err(|_e| "Kann Datei nicht lesen")?;
|
||||
|
||||
print_items(&items);
|
||||
}
|
||||
@ -188,7 +187,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
writer_builder = writer_builder.delimiter(b';');
|
||||
}
|
||||
let mut writer = writer_builder
|
||||
.from_path(Path::new(&output))
|
||||
.from_path(output.as_path())
|
||||
.expect("writeable file");
|
||||
|
||||
items
|
||||
@ -200,7 +199,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
"{} Conditions für das Jahr {} in Datei '{}' exportiert",
|
||||
items.len(),
|
||||
year,
|
||||
output
|
||||
output.to_str().unwrap_or_default()
|
||||
))
|
||||
.green()
|
||||
.to_string(),
|
||||
@ -243,8 +242,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let _ = term.clear_last_lines(1);
|
||||
|
||||
let csv_items = opal::OpalCsvFile::export(Path::new(&file))
|
||||
.map_err(|_e| "Kann Datei nicht lesen")?;
|
||||
let csv_items =
|
||||
opal::OpalCsvFile::export(file.as_path()).map_err(|_e| "Kann Datei nicht lesen")?;
|
||||
|
||||
let mut not_in_csv = db_items
|
||||
.iter()
|
||||
@ -263,7 +262,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
"{} Conditions aus der Datenbank für das Jahr {} - aber nicht in Datei '{}'",
|
||||
not_in_csv.len(),
|
||||
year,
|
||||
file
|
||||
file.to_str().unwrap_or_default()
|
||||
))
|
||||
.green()
|
||||
.to_string(),
|
||||
@ -321,7 +320,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
&style(format!(
|
||||
"{} Conditions aus Datei '{}' - aber nicht in der Datenbank für das Jahr {}",
|
||||
not_in_db.len(),
|
||||
file,
|
||||
file.to_str().unwrap_or_default(),
|
||||
year
|
||||
))
|
||||
.green()
|
||||
|
Loading…
x
Reference in New Issue
Block a user