Add macro for checking if modifiers were entered & panic through clap

pull/4/head
sgoudham 3 years ago
parent c27ce62b97
commit 45b864f5ea

@ -1,3 +1,5 @@
use std::panic::set_hook;
use clap::{Arg, ArgGroup, ErrorKind}; use clap::{Arg, ArgGroup, ErrorKind};
use uwuifyy::UwUify; use uwuifyy::UwUify;
@ -99,13 +101,16 @@ macro_rules! clap_panic {
}; };
} }
macro_rules! is_runtime {
($faces:expr, $actions:expr, $stutters:expr) => {
$faces > 0 || $actions > 0 || $stutters > 0
};
}
fn main() { fn main() {
std::panic::set_hook(Box::new(|info| { set_hook(Box::new(|info| clap_panic!(info)));
clap_panic!(info);
}));
let matches = app!().get_matches();
// panicing here ensures that the error is passed to the hook above instead of to stdout. let matches = app!().get_matches();
match UwUify::new( match UwUify::new(
matches.value_of("text"), matches.value_of("text"),
matches.value_of("infile"), matches.value_of("infile"),
@ -115,10 +120,15 @@ fn main() {
matches.value_of("actions"), matches.value_of("actions"),
matches.value_of("stutters"), matches.value_of("stutters"),
matches.is_present("random"), matches.is_present("random"),
is_runtime!(
matches.occurrences_of("faces"),
matches.occurrences_of("actions"),
matches.occurrences_of("stutters")
),
) )
.uwuify() .uwuify()
{ {
Err(e) => clap_panic!(e), Err(err) => clap_panic!(err),
_ => {} _ => {}
}; };
} }
@ -133,4 +143,4 @@ fn is_between_zero_and_one(input: &str) -> Result<(), &'static str> {
return Ok(()); return Ok(());
} }
Err("The value must be between 0.0 and 1.0") Err("The value must be between 0.0 and 1.0")
} }
Loading…
Cancel
Save