Skip to content

Commit

Permalink
Add --base-path feature
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tanuva committed Dec 19, 2023
1 parent 3e932c1 commit e2bf95e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion escl-scan-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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<PathBuf>,

/// Output document format
#[arg(short, long, value_enum, default_value = "jpg")]
output_format: CliOutputFormat,
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit e2bf95e

Please sign in to comment.