use std::{io, path::PathBuf};
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum CliError {
#[error("RF_CLI_IO: {action} `{path}`: {source}")]
Io {
action: &'static str,
path: PathBuf,
source: io::Error,
},
#[error("RF_CLI_INVALID_NAME: `{name}` cannot form a safe Rust identifier")]
InvalidName {
name: String,
},
#[error("RF_CLI_FILE_CONFLICT: refusing to overwrite `{path}`")]
FileConflict {
path: PathBuf,
},
#[error("RF_CLI_SOURCE_PARSE: cannot safely update `{path}`: {message}")]
SourceParse {
path: PathBuf,
message: String,
},
#[error("RF_CLI_COMMAND_FAILED: `{program}` exited with status {status}")]
CommandFailed {
program: String,
status: String,
},
}
impl CliError {
pub(crate) fn io(action: &'static str, path: impl Into<PathBuf>, source: io::Error) -> Self {
Self::Io {
action,
path: path.into(),
source,
}
}
}