reject lowercase exts bc they don't worky

This commit is contained in:
Lynne Megido 2021-04-29 17:02:28 +10:00
parent 32edcc0c92
commit a60a19191a
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
2 changed files with 12 additions and 4 deletions

4
Cargo.lock generated
View file

@ -505,9 +505,9 @@ dependencies = [
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.2.6" version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8270314b5ccceb518e7e578952f0b72b88222d02e8f77f5ecf7abbb673539041" checksum = "85dd92e586f7355c633911e11f77f3d12f04b1b1bd76a198bd34ae3af8341ef2"
dependencies = [ dependencies = [
"bitflags", "bitflags",
] ]

View file

@ -48,7 +48,7 @@ pub struct Parameters {
/// Only examine files with these extensions. /// 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 /// 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`). /// 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<Vec<StringType>>, pub exts: Option<Vec<StringType>>,
/// Use these preset lists of extensions as the search filter (comma-separated list). /// 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. /// Don't scan files with these extensions.
/// This option takes precedence over extensions specified with `-e` or `-E`. /// 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<Vec<StringType>>, pub exclude: Option<Vec<StringType>>,
/// Exclude files using a preset list of extensions. /// Exclude files using a preset list of extensions.
@ -103,6 +103,14 @@ pub struct Parameters {
pub dirs: PathBuf, 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. /// Further options relating to scanning.
#[derive(PartialEq, Debug)] #[derive(PartialEq, Debug)]
pub struct ScanOpts { pub struct ScanOpts {