add feature flags

This commit is contained in:
Ren Kararou 2023-11-12 21:19:42 -06:00
parent a4f1a9ed67
commit 9a9ad14e07
Signed by: spicywolf
GPG key ID: B0BA4EEC0714F8E6
2 changed files with 13 additions and 1 deletions

View file

@ -5,8 +5,12 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["image"]
image = ["dep:image"]
[dependencies] [dependencies]
clap = { version = "4.4.8", features = ["derive"] } clap = { version = "4.4.8", features = ["derive"] }
image = "0.24.7" image = { version = "0.24.7", optional = true}
rand = "0.8.5" rand = "0.8.5"
walkdir = "2.4.0" walkdir = "2.4.0"

View file

@ -1,6 +1,7 @@
#![feature(io_error_more)] #![feature(io_error_more)]
use clap::Parser; use clap::Parser;
#[cfg(feature = "image")]
use image::GenericImageView; use image::GenericImageView;
use rand::seq::SliceRandom; use rand::seq::SliceRandom;
use walkdir::WalkDir; use walkdir::WalkDir;
@ -21,8 +22,10 @@ use std::result::Result;
struct Args { struct Args {
#[arg(long, short)] #[arg(long, short)]
out: Option<String>, // Output file out: Option<String>, // Output file
#[cfg(feature = "image")]
#[arg(long)] #[arg(long)]
width: Option<u32>, width: Option<u32>,
#[cfg(feature = "image")]
#[arg(long)] #[arg(long)]
height: Option<u32>, height: Option<u32>,
dir: Option<Vec<String>>, // Directories to Pick From dir: Option<Vec<String>>, // Directories to Pick From
@ -67,6 +70,7 @@ fn main() -> Result<(), Error> {
"Directory(s) searched are emtpy!", "Directory(s) searched are emtpy!",
)); ));
} }
#[cfg(feature = "image")]
let pick: &PathBuf = if args.width.clone().is_some() || args.height.clone().is_some() { let pick: &PathBuf = if args.width.clone().is_some() || args.height.clone().is_some() {
let mut chk = true; let mut chk = true;
let mut p: &PathBuf = &files[0]; let mut p: &PathBuf = &files[0];
@ -104,6 +108,10 @@ fn main() -> Result<(), Error> {
.choose(&mut rand::thread_rng()) .choose(&mut rand::thread_rng())
.expect("error picking random file") .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() { 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 // 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. // locking up large amounts of system ram running on a large file.