#[derive(Debug, Clone)]
pub struct RepoInfo {
pub owner: &'static str,
pub name: &'static str,
}
impl RepoInfo {
#[must_use]
pub const fn new(owner: &'static str, name: &'static str) -> Self {
Self { owner, name }
}
}
#[derive(Debug, Clone)]
pub struct DoctorCheck {
pub name: String,
pub passed: bool,
pub message: Option<String>,
}
impl DoctorCheck {
#[must_use]
pub fn pass(name: impl Into<String>) -> Self {
Self {
name: name.into(),
passed: true,
message: None,
}
}
#[must_use]
pub fn fail(name: impl Into<String>, message: impl Into<String>) -> Self {
Self {
name: name.into(),
passed: false,
message: Some(message.into()),
}
}
pub fn file_exists(path: impl AsRef<std::path::Path>) -> Self {
let path_ref = path.as_ref();
if path_ref.exists() && path_ref.is_file() {
Self::pass(format!("File exists: {}", path_ref.display()))
} else {
Self::fail(
format!("File check: {}", path_ref.display()),
format!("File not found: {}", path_ref.display()),
)
}
}
pub fn dir_exists(path: impl AsRef<std::path::Path>) -> Self {
let path_ref = path.as_ref();
if path_ref.exists() && path_ref.is_dir() {
Self::pass(format!("Directory exists: {}", path_ref.display()))
} else {
Self::fail(
format!("Directory check: {}", path_ref.display()),
format!("Directory not found: {}", path_ref.display()),
)
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_repo_info_creation() {
let repo = RepoInfo::new("workhelix", "prompter");
assert_eq!(repo.owner, "workhelix");
assert_eq!(repo.name, "prompter");
}
#[test]
fn test_doctor_check_pass() {
let check = DoctorCheck::pass("test check");
assert!(check.passed);
assert_eq!(check.name, "test check");
assert!(check.message.is_none());
}
#[test]
fn test_doctor_check_fail() {
let check = DoctorCheck::fail("test check", "error message");
assert!(!check.passed);
assert_eq!(check.name, "test check");
assert_eq!(check.message, Some("error message".to_string()));
}
}