use crate::cli::OutputFormat;
use crate::output::ExitCode;
use crate::{CatCmd, Output};
use clap::builder::StyledStr;
use clap::ColorChoice;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
pub struct Error(Output);
impl Error {
#[must_use]
pub fn render(&self, format: OutputFormat) -> String {
self.0.render(format)
}
}
impl From<anyhow::Error> for Error {
fn from(err: anyhow::Error) -> Self {
Self(Output::Cat(CatCmd::new(
StyledStr::from(format!("{err}\n")),
ExitCode::Error,
ColorChoice::Auto,
)))
}
}