From 16f5ed4fc505f0f12946aca5c7514472adbd1fe3 Mon Sep 17 00:00:00 2001 From: gennyble Date: Tue, 7 Oct 2025 20:54:42 -0500 Subject: allow failed parse arg in error --- src/lib.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index de54b89..d27c8de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -101,9 +101,10 @@ impl Scurvy { if let Some((fail, mut check)) = formula.check_fn { if !check(&o) { let pair = self.get_pair(key).unwrap(); - let str = fail.replace("[opt]", pair.key.preferred_key()); + let parsefail = + format_parse_fail(fail.into(), pair.key.preferred_key(), got); - eprintln!("{str}"); + eprintln!("{parsefail}"); std::process::exit(-1); } @@ -113,7 +114,10 @@ impl Scurvy { Some(o) } Err(_e) => { - eprintln!("{}", formula.failure); + let pair = self.get_pair(key).unwrap(); + let fail = format_parse_fail(formula.failure.into(), pair.key.preferred_key(), got); + + eprintln!("{fail}"); std::process::exit(-1); } } @@ -154,6 +158,10 @@ impl Scurvy { } } +pub(crate) fn format_parse_fail(string: Cow<'static, str>, key: &str, arg: &str) -> String { + string.replace("[opt]", key).replace("[arg]", arg) +} + pub struct Argument { keys: Vec, arg_name: Option<&'static str>, -- cgit 1.4.1-3-g733a5