summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/lib.rs14
1 files changed, 11 insertions, 3 deletions
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<String>,
 	arg_name: Option<&'static str>,