use super::Recipe;
use anyhow::Result;
use std::path::Path;
pub fn load_from_dir(dir: &Path) -> Result<Vec<Recipe>> {
let mut recipes = Vec::new();
if !dir.exists() {
return Ok(recipes);
}
for entry in std::fs::read_dir(dir)? {
let entry = entry?;
if entry
.path()
.extension()
.map(|e| e == "toml")
.unwrap_or(false)
{
let content = std::fs::read_to_string(entry.path())?;
let recipe: Recipe = toml::from_str(&content)?;
recipes.push(recipe);
}
}
Ok(recipes)
}