add feature flags
This commit is contained in:
parent
a4f1a9ed67
commit
9a9ad14e07
|
@ -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"
|
||||
|
|
|
@ -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<String>, // Output file
|
||||
#[cfg(feature = "image")]
|
||||
#[arg(long)]
|
||||
width: Option<u32>,
|
||||
#[cfg(feature = "image")]
|
||||
#[arg(long)]
|
||||
height: Option<u32>,
|
||||
dir: Option<Vec<String>>, // 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.
|
||||
|
|
Loading…
Reference in a new issue