use pound::Parse;
#[derive(Parse, Debug)]
#[pound(name = "grab", version = "0.1.0")]
#[allow(dead_code, reason = "demo just prints the parsed struct")]
struct Grab {
url: Vec<String>,
#[pound(short, long)]
output: Option<String>,
#[pound(short, long)]
force: bool,
#[pound(short, long, count)]
verbose: u8,
#[pound(short, long, default = "4", min = "1", max = "64", validate = "power_of_two")]
jobs: u32,
}
#[allow(
clippy::missing_const_for_fn,
clippy::trivially_copy_pass_by_ref,
reason = "validator hooks receive the parsed field by reference"
)]
fn power_of_two(value: &u32) -> Result<(), &'static str> {
if value.is_power_of_two() {
Ok(())
} else {
Err("must be a power of two")
}
}
fn main() {
let grab = Grab::parse();
println!("{grab:?}");
}