Improve clap error message

This commit is contained in:
Austen Adler 2022-01-23 23:06:30 -05:00
parent f4b47fbe12
commit e9e6fa6c6f

View File

@ -44,12 +44,7 @@ fn send_message(msg: &KakMessage) {
}
fn run() -> Result<(), KakMessage> {
let options = Options::try_parse().map_err(|e| {
KakMessage(
"Error parsing arguments".to_string(),
Some(format!("Could not parse: {:?}", e)),
)
})?;
let options = Options::try_parse()?;
let replacement_re = options.regex;
@ -116,6 +111,15 @@ impl From<std::io::Error> for KakMessage {
}
}
impl From<clap::Error> for KakMessage {
fn from(err: clap::Error) -> Self {
Self(
"Error parsing arguments".to_string(),
Some(format!("{:?}", err)), // Some(err.message.pieces.map(|p| p.0).join()),
)
}
}
impl From<String> for KakMessage {
fn from(err: String) -> Self {
Self(err, None)