From e2bf95ebdd7bef386d4d531701f19ba5a91ee2b1 Mon Sep 17 00:00:00 2001 From: Marcel Kummer Date: Tue, 19 Dec 2023 15:11:53 +0100 Subject: [PATCH] Add --base-path feature Sets the base path for the given output file name. I intend to use this in shell aliases where a base path is configured in the alias. I then only need to specify a file name when invoking the alias, such as this: alias scan-invoice="escl-scan -b ~/archive/invoices" $ scan-invoice 1998/loveparade.pdf --- escl-scan-cli/src/main.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/escl-scan-cli/src/main.rs b/escl-scan-cli/src/main.rs index 5041470..bf9e1f3 100644 --- a/escl-scan-cli/src/main.rs +++ b/escl-scan-cli/src/main.rs @@ -11,6 +11,7 @@ use clap::{Args, Parser, ValueEnum}; use scan::scanner::Scanner; use scan::scannerfinder::ScannerFinder; use scan::structs::{self}; +use std::path::PathBuf; use std::process::exit; #[derive(Clone, ValueEnum)] @@ -82,6 +83,10 @@ struct Cli { #[arg(value_name = "OUTPUT_FILE_NAME", default_value = "scan.jpg")] output_file_name: String, + /// Base path for output file + #[arg(short = 'b', long = "base-path")] + output_base_path: Option, + /// Output document format #[arg(short, long, value_enum, default_value = "jpg")] output_format: CliOutputFormat, @@ -182,7 +187,17 @@ fn main() { scan_settings.scan_regions = args.input_format.into(); scan_settings.feed_direction = structs::FeedDirection::ShortEdgeFeed.into(); - if let Err(err) = scanner.scan(&scan_settings, &args.output_file_name) { + let destination_file_name = if let Some(base_path) = args.output_base_path { + base_path + .join(args.output_file_name) + .to_str() + .expect("Path is printable") + .to_string() + } else { + args.output_file_name + }; + + if let Err(err) = scanner.scan(&scan_settings, &destination_file_name) { eprintln!("Failed to scan: {err:?}"); exit(1); }