From 9f5188ce5d3c37853b0bd5698f9910422b14d2c0 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Thu, 23 May 2024 08:27:24 +0200 Subject: [PATCH] feat: use PathBuf as argument type --- src/cli.rs | 7 ++++--- src/main.rs | 17 ++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 09cbe35..34b9783 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -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")] diff --git a/src/main.rs b/src/main.rs index ad4e249..50d368f 100644 --- a/src/main.rs +++ b/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> { 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> { 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> { "{} 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> { 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> { "{} 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> { &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()