nestrs-cli-rs 0.1.0

Rust port of the Nest CLI for the nestrs organization.
Documentation
//! Shared crate error types.

use std::fmt;
use std::io;

pub type Result<T> = std::result::Result<T, CliError>;

#[derive(Debug)]
pub enum CliError {
    Io(io::Error),
    InvalidConfiguration(String),
    UnsupportedPackageManager(String),
    UnsupportedCommand(String),
    RunnerFailed { command: String, reason: String },
}

impl fmt::Display for CliError {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Io(error) => write!(formatter, "{error}"),
            Self::InvalidConfiguration(message) => {
                write!(formatter, "Invalid Nest CLI configuration: {message}")
            }
            Self::UnsupportedPackageManager(name) => {
                write!(formatter, "Package manager {name} is not managed.")
            }
            Self::UnsupportedCommand(command) => {
                write!(formatter, "Unsupported Nest CLI command: {command}")
            }
            Self::RunnerFailed { command, reason } => {
                write!(formatter, "Failed to execute command `{command}`: {reason}")
            }
        }
    }
}

impl std::error::Error for CliError {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Self::Io(error) => Some(error),
            _ => None,
        }
    }
}

impl From<io::Error> for CliError {
    fn from(error: io::Error) -> Self {
        Self::Io(error)
    }
}