#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PromptError {
pub name: String,
pub message: String,
}
impl PromptError {
pub fn new(name: impl Into<String>, message: impl Into<String>) -> Self {
Self {
name: name.into(),
message: message.into(),
}
}
}
impl std::fmt::Display for PromptError {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str(&self.message)
}
}
impl std::error::Error for PromptError {}
pub fn gracefully_exit_on_prompt_error(error: PromptError) -> Result<(), PromptError> {
if error.name == "ExitPromptError" {
std::process::exit(1);
}
Err(error)
}