From 994ac8cf594ab66a3af4dde8dbd664f91ed5d9ab Mon Sep 17 00:00:00 2001 From: ascendforever Date: Sun, 13 Oct 2024 11:53:52 -0400 Subject: [PATCH] renames --- src/main.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index d0433d4..39b6ec5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ use std::os::linux::fs::MetadataExt as MetadataExtLinux; use crate::structopt::StructOpt; +macro_rules! s_default_target_separator { () => { ";" } } fn main() -> Result<(), Box> { let (run_paths, cfg) = process_args(); @@ -29,7 +30,7 @@ struct Config { #[derive(StructOpt)] #[structopt( about="Hardlink duplicate files recursively", - usage=concat!(env!("CARGO_PKG_NAME"), " [OPTION]... TARGET... [';' TARGET...]") + usage=concat!(env!("CARGO_PKG_NAME"), " [OPTION]... TARGET... ['", s_default_target_separator!(), "' TARGET...]") )] struct CLIArguments { #[structopt(short, long, parse(from_occurrences), @@ -57,7 +58,7 @@ struct CLIArguments { min_size: Option, #[structopt(short, long, value_name="SEPARATOR", - help="Separator between sets of targets (default: ';')")] + help=concat!("Separator between sets of targets (default: ", s_default_target_separator!(), ")"))] separator: Option, #[structopt(long, value_name="FILE", @@ -91,11 +92,11 @@ fn prompt_confirm(run_targets: &Vec>) -> bool { } -fn read_argument_file(arg_file: &Path, dest: &mut Vec) -> Result<(), String> { - if !arg_file.is_file() { - return Err(format!("File does not exist or is not a normal file ({})", shlex::quote(&arg_file.to_string_lossy()))); +fn read_file_lines(path: &Path, dest: &mut Vec) -> Result<(), String> { + if !path.is_file() { + return Err(format!("File does not exist or is not a normal file ({})", shlex::quote(&path.to_string_lossy()))); } - if let Ok(f) = std::fs::File::open(arg_file) { + if let Ok(f) = std::fs::File::open(path) { let reader = BufReader::new(f); for line in reader.lines() { match line { @@ -105,12 +106,12 @@ fn read_argument_file(arg_file: &Path, dest: &mut Vec) -> Result<(), Str } Ok(()) } else { - Err(format!("Could not open {}", shlex::quote(&arg_file.to_string_lossy()))) + Err(format!("Could not open {}", shlex::quote(&path.to_string_lossy()))) } } -/// exits on error +/// may exit fn process_args() -> (Vec>, Config) { let mut args = CLIArguments::from_args(); let verbosity = args.verbose - args.quiet; @@ -121,13 +122,13 @@ fn process_args() -> (Vec>, Config) { std::process::exit(1); } let path = Path::new(&arg_file); - if let Err(s) = read_argument_file(path, &mut args.targets) { + if let Err(s) = read_file_lines(path, &mut args.targets) { eprintln!("Error reading argument file: {}", s); std::process::exit(1); } } - let run_targets: Vec> = split_vec(&args.targets, &args.separator.unwrap_or(";".to_string())); + let run_targets: Vec> = split_vec(&args.targets, &args.separator.unwrap_or(s_default_target_separator!().to_string())); if run_targets.is_empty() { if verbosity > 0 {