use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum VersionFileError {
#[error("file not found: {}", .0.display())]
FileNotFound(PathBuf),
#[error("no version field found")]
NoVersionField,
#[error("write failed: {0}")]
WriteFailed(#[source] std::io::Error),
#[error("read failed: {0}")]
ReadFailed(#[source] std::io::Error),
#[error("invalid regex: {0}")]
InvalidRegex(String),
}
pub trait VersionFile {
fn name(&self) -> &str;
fn filenames(&self) -> &[&str];
fn detect(&self, content: &str) -> bool;
fn read_version(&self, content: &str) -> Option<String>;
fn write_version(&self, content: &str, new_version: &str) -> Result<String, VersionFileError>;
fn extra_info(&self, _old_content: &str, _new_content: &str) -> Option<String> {
None
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UpdateResult {
pub path: PathBuf,
pub name: String,
pub old_version: String,
pub new_version: String,
pub extra: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DetectedFile {
pub path: PathBuf,
pub name: String,
pub old_version: String,
}
#[derive(Debug, Clone)]
pub struct CustomVersionFile {
pub path: PathBuf,
pub pattern: String,
}
pub use crate::scan::{detect_version_files, update_version_files};