From 45b864f5ea084eee18478e71cfe0398995c8d92b Mon Sep 17 00:00:00 2001 From: sgoudham Date: Sun, 30 Jan 2022 23:07:12 +0000 Subject: [PATCH] Add macro for checking if modifiers were entered & panic through clap --- src/main.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 480e3d0..d6ac0e1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +use std::panic::set_hook; + use clap::{Arg, ArgGroup, ErrorKind}; 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() { - std::panic::set_hook(Box::new(|info| { - clap_panic!(info); - })); - let matches = app!().get_matches(); + set_hook(Box::new(|info| clap_panic!(info))); - // panicing here ensures that the error is passed to the hook above instead of to stdout. + let matches = app!().get_matches(); match UwUify::new( matches.value_of("text"), matches.value_of("infile"), @@ -115,10 +120,15 @@ fn main() { matches.value_of("actions"), matches.value_of("stutters"), matches.is_present("random"), + is_runtime!( + matches.occurrences_of("faces"), + matches.occurrences_of("actions"), + matches.occurrences_of("stutters") + ), ) .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(()); } Err("The value must be between 0.0 and 1.0") -} +} \ No newline at end of file