#![allow(unused_imports)]
#![allow(dead_code)]
pub mod condition;
pub mod context;
pub mod dependency;
pub mod executor;
pub mod models;
pub mod parser;
pub mod reporter;
pub mod testing;
pub mod validator;
#[cfg(test)]
mod tests;
pub use executor::{CollectionExecutor, ExecutionOptions};
pub use parser::parse_collection;
pub use reporter::ConsoleReporter;
pub use validator::validate_collection;
use anyhow::Result;
use std::path::{Path, PathBuf};
pub fn list_collections(collections_dir: &Path) -> Result<Vec<PathBuf>> {
let mut collections = Vec::new();
if !collections_dir.exists() {
return Ok(collections);
}
find_yaml_files(collections_dir, &mut collections)?;
collections.sort();
Ok(collections)
}
fn find_yaml_files(dir: &Path, collections: &mut Vec<PathBuf>) -> Result<()> {
for entry in std::fs::read_dir(dir)? {
let entry = entry?;
let path = entry.path();
if path.is_dir() {
find_yaml_files(&path, collections)?;
} else if path.is_file() {
if let Some(ext) = path.extension() {
if ext == "yaml" || ext == "yml" {
collections.push(path);
}
}
}
}
Ok(())
}
pub fn find_collection(collections_dir: &Path, name: &str) -> Result<PathBuf> {
let name = name.strip_prefix("collections/").unwrap_or(name);
let direct_path = collections_dir.join(name);
if direct_path.exists() && direct_path.is_file() {
return Ok(direct_path);
}
if !name.ends_with(".yaml") && !name.ends_with(".yml") {
for ext in &["yaml", "yml"] {
let path = collections_dir.join(format!("{}.{}", name, ext));
if path.exists() {
return Ok(path);
}
}
}
if name.contains('/') {
return Err(crate::core::api::ApiError::ValidationError(format!(
"Collection '{}' not found in {:?}",
name, collections_dir
))
.into());
}
for ext in &["yaml", "yml"] {
let path = collections_dir.join(format!("{}.{}", name, ext));
if path.exists() {
return Ok(path);
}
}
Err(crate::core::api::ApiError::ValidationError(format!(
"Collection '{}' not found in {:?}",
name, collections_dir
))
.into())
}