From 9a9ad14e0702d82edcd0c6006ab8ea78d5fb3172 Mon Sep 17 00:00:00 2001 From: Ren Kararou Date: Sun, 12 Nov 2023 21:19:42 -0600 Subject: [PATCH] add feature flags --- Cargo.toml | 6 +++++- src/main.rs | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 383bae9..0a433ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,8 +5,12 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +default = ["image"] +image = ["dep:image"] + [dependencies] clap = { version = "4.4.8", features = ["derive"] } -image = "0.24.7" +image = { version = "0.24.7", optional = true} rand = "0.8.5" walkdir = "2.4.0" diff --git a/src/main.rs b/src/main.rs index 2f73e3a..7a8183f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ #![feature(io_error_more)] use clap::Parser; +#[cfg(feature = "image")] use image::GenericImageView; use rand::seq::SliceRandom; use walkdir::WalkDir; @@ -21,8 +22,10 @@ use std::result::Result; struct Args { #[arg(long, short)] out: Option, // Output file + #[cfg(feature = "image")] #[arg(long)] width: Option, + #[cfg(feature = "image")] #[arg(long)] height: Option, dir: Option>, // Directories to Pick From @@ -67,6 +70,7 @@ fn main() -> Result<(), Error> { "Directory(s) searched are emtpy!", )); } + #[cfg(feature = "image")] let pick: &PathBuf = if args.width.clone().is_some() || args.height.clone().is_some() { let mut chk = true; let mut p: &PathBuf = &files[0]; @@ -104,6 +108,10 @@ fn main() -> Result<(), Error> { .choose(&mut rand::thread_rng()) .expect("error picking random file") }; + #[cfg(not(feature = "image"))] + let pick = files + .choose(&mut rand::thread_rng()) + .expect("error picking random file"); if let Some(out) = args.out.to_owned() { // TODO: setup a constant size buffer and read/write that many bytes at a time to prevent // locking up large amounts of system ram running on a large file.