use std::fs;
use std::path::Path;
use serde::Serialize;
pub mod dispatch;
pub mod fixtures;
#[cfg(test)]
mod golden_tests;
pub mod grouping;
pub mod orchestrate;
pub mod runbook;
pub mod staging;
pub mod steps;
mod util;
#[derive(Debug, thiserror::Error)]
pub enum RunError {
#[error("{0}")]
Message(String),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error(transparent)]
Json(#[from] serde_json::Error),
#[error(transparent)]
Validation(#[from] crate::validation::ValidationError),
}
impl RunError {
pub fn msg(text: impl Into<String>) -> Self {
RunError::Message(text.into())
}
}
pub(crate) fn write_json<T: Serialize>(path: &Path, value: &T) -> Result<(), RunError> {
let mut text = serde_json::to_string_pretty(value)?;
text.push('\n');
std::fs::write(path, text)?;
Ok(())
}
pub(crate) fn copy_entry(src: &Path, dst: &Path) -> Result<(), RunError> {
if fs::metadata(src)?.is_dir() {
copy_dir_recursive(src, dst)
} else {
fs::copy(src, dst)?;
Ok(())
}
}
pub(crate) fn copy_dir_recursive(src: &Path, dst: &Path) -> Result<(), RunError> {
fs::create_dir_all(dst)?;
for entry in fs::read_dir(src)? {
let entry = entry?;
let from = entry.path();
let to = dst.join(entry.file_name());
if entry.file_type()?.is_dir() {
copy_dir_recursive(&from, &to)?;
} else {
fs::copy(&from, &to)?;
}
}
Ok(())
}