use std::process::{ExitCode, Termination};

use crate::err::Error;

#[repr(u8)]
pub enum ProcRes {
  Success,
  Error(Error)
}

impl Termination for ProcRes {
  fn report(self) -> ExitCode {
    match self {
      Self::Success => {
        //eprintln!("Process terminated successfully");
        ExitCode::from(0)
      }
      Self::Error(e) => {
        eprintln!("Abnormal termination: {e}");
        ExitCode::from(1)
      }
    }
  }
}

impl<T> From<Result<T, Error>> for ProcRes {
  fn from(res: Result<T, Error>) -> Self {
    match res {
      Ok(_) => Self::Success,
      Err(e) => Self::Error(e)
    }
  }
}

// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :
