From a60a19191a26ea9709c20bb80fef357d1dce987f Mon Sep 17 00:00:00 2001 From: Lynne Date: Thu, 29 Apr 2021 17:02:28 +1000 Subject: [PATCH] reject lowercase exts bc they don't worky --- Cargo.lock | 4 ++-- src/parameters.rs | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f3d30e1..74ffa4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -505,9 +505,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8270314b5ccceb518e7e578952f0b72b88222d02e8f77f5ecf7abbb673539041" +checksum = "85dd92e586f7355c633911e11f77f3d12f04b1b1bd76a198bd34ae3af8341ef2" dependencies = [ "bitflags", ] diff --git a/src/parameters.rs b/src/parameters.rs index 00d047a..d68bdcf 100644 --- a/src/parameters.rs +++ b/src/parameters.rs @@ -48,7 +48,7 @@ pub struct Parameters { /// Only examine files with these extensions. /// Multiple extensions can be specified by either using the flag multiple times (`-e jpg -e png -e gif`), or by /// separating them with commas (`-e jpg,png,gif`). - #[clap(short, long, use_delimiter = true, require_delimiter = true, value_name = "ext")] + #[clap(short, long, use_delimiter = true, require_delimiter = true, value_name = "ext", validator = lowercase_exts)] pub exts: Option>, /// Use these preset lists of extensions as the search filter (comma-separated list). @@ -59,7 +59,7 @@ pub struct Parameters { /// Don't scan files with these extensions. /// This option takes precedence over extensions specified with `-e` or `-E`. - #[clap(short = 'x', long, use_delimiter = true, require_delimiter = true, value_name = "ext")] + #[clap(short = 'x', long, use_delimiter = true, require_delimiter = true, value_name = "ext", validator = lowercase_exts)] pub exclude: Option>, /// Exclude files using a preset list of extensions. @@ -103,6 +103,14 @@ pub struct Parameters { pub dirs: PathBuf, } +fn lowercase_exts(exts: &str) -> Result<(), String> { + // TODO: i would much rather accept uppercase exts and convert them to lowercase than just rejecting lowercase exts... + if exts.to_lowercase() != exts { + return Err(String::from("Supplied extensions must be lowercase")) + } + Ok(()) +} + /// Further options relating to scanning. #[derive(PartialEq, Debug)] pub struct ScanOpts {