use std::path::{Path, PathBuf};
mod ship;
mod version;
pub use ship::{ship, ShipOptions, ShipReport};
pub use version::{bump, locate, next_version, show, Bump, ProjectKind, VersionInfo};
#[derive(Debug, thiserror::Error)]
pub enum ShipError {
#[error("no version file in {0} (looked for Cargo.toml, pyproject.toml)")]
NoVersionFile(PathBuf),
#[error("{path}: no version field found ({detail})")]
NoVersionField {
path: PathBuf,
detail: String,
},
#[error("{path}: invalid TOML: {source}")]
Toml {
path: PathBuf,
source: toml_edit::TomlError,
},
#[error("{version:?} is not a valid semantic version: {source}")]
Semver {
version: String,
source: semver::Error,
},
#[error("reading {path}: {source}")]
Read {
path: PathBuf,
source: std::io::Error,
},
#[error("writing {path}: {source}")]
Write {
path: PathBuf,
source: std::io::Error,
},
#[error("the working tree at {dir} has uncommitted changes; commit or stash them before ship")]
DirtyWorkingTree {
dir: PathBuf,
},
#[error("git {op} failed: {detail}")]
Git {
op: String,
detail: String,
},
}
pub(crate) fn read(path: &Path) -> Result<String, ShipError> {
std::fs::read_to_string(path).map_err(|source| ShipError::Read {
path: path.to_path_buf(),
source,
})
}
pub(crate) fn write(path: &Path, contents: &str) -> Result<(), ShipError> {
std::fs::write(path, contents).map_err(|source| ShipError::Write {
path: path.to_path_buf(),
source,
})
}