how.rs/src/termination.rs

38 lines
821 B
Rust
Raw Normal View History

2022-07-21 20:40:44 -04:00
use std::process::{ExitCode, Termination};
use crate::How;
pub enum TerminationResult {
Ok,
Err(How),
}
impl Termination for TerminationResult {
2022-09-06 07:47:11 -04:00
#[inline]
2022-07-21 20:40:44 -04:00
fn report(self) -> ExitCode {
match self {
Self::Ok => ExitCode::SUCCESS,
Self::Err(e) => {
use std::io::Write;
let _ = writeln!(
std::io::stderr(),
2023-07-02 15:08:30 -04:00
concat!("\n", ansee::styled!(bold, italic, "But, how?"), "\n{}"),
e
);
2022-07-21 20:40:44 -04:00
ExitCode::FAILURE
}
}
}
}
impl From<Result<(), How>> for TerminationResult {
2022-09-06 07:47:11 -04:00
#[inline]
2022-07-21 20:40:44 -04:00
fn from(value: Result<(), How>) -> Self {
match value {
Ok(()) => Self::Ok,
Err(e) => Self::Err(e),
}
}
}