diff --git a/modular-recipes/code/recipe-loader/.gitignore b/modular-recipes/code/recipe-loader/.gitignore new file mode 100644 index 0000000..869df07 --- /dev/null +++ b/modular-recipes/code/recipe-loader/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock \ No newline at end of file diff --git a/modular-recipes/code/recipe-loader/Cargo.toml b/modular-recipes/code/recipe-loader/Cargo.toml new file mode 100644 index 0000000..f6d8e00 --- /dev/null +++ b/modular-recipes/code/recipe-loader/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "recipe-loader" +version = "0.1.0" +edition = "2021" + +[dependencies] +clap = { version = "^4.5.26", features = ["derive"] } +recipe = {path="../recipe"} +toml = "0.8.19" diff --git a/modular-recipes/code/recipe-loader/src/main.rs b/modular-recipes/code/recipe-loader/src/main.rs new file mode 100644 index 0000000..def00bb --- /dev/null +++ b/modular-recipes/code/recipe-loader/src/main.rs @@ -0,0 +1,58 @@ +use clap::Parser; +use recipe::TomlRecipe; + +use std::fs; +use std::path::Path; + +#[derive(Parser, Debug)] +struct Cli { + #[arg(long)] + /// the recipe you'd like to make (needs to be in the repo) + recipe: String, + + #[arg(long)] + /// the repository of your recipes + repo: String, +} + +pub struct LoadedEnvironment { + recipes: Vec, +} + +impl Default for LoadedEnvironment { + fn default() -> Self { + Self { + recipes: Vec::new(), + } + } +} + +impl LoadedEnvironment { + pub fn new(repo: &Path) -> Self { + let paths = fs::read_dir(repo).unwrap(); + let mut env = LoadedEnvironment::default(); + for path in paths { + let path = path.expect("Failed to unwrap path"); + env.recipes.push(TomlRecipe::new(&path.path())) + } + env + } + + pub fn print(&self) { + for recipe in &self.recipes { + recipe.print(); + println!(); + } + } +} + +pub fn main() { + let cli = Cli::parse(); + let repo = Path::new(&cli.repo); + let env = LoadedEnvironment::new(repo); + env.print(); + // let recipe = TomlRecipe::default(); + // recipe.print(); + + println!("{}", repo.display()); +} diff --git a/modular-recipes/code/recipe/.gitignore b/modular-recipes/code/recipe/.gitignore new file mode 100644 index 0000000..869df07 --- /dev/null +++ b/modular-recipes/code/recipe/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock \ No newline at end of file diff --git a/modular-recipes/code/recipe/Cargo.toml b/modular-recipes/code/recipe/Cargo.toml new file mode 100644 index 0000000..a135500 --- /dev/null +++ b/modular-recipes/code/recipe/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "recipe" +version = "0.1.0" +edition = "2021" + +[dependencies] +serde = { version = "1.0.215", features = ["derive"] } +toml = "0.8.19" \ No newline at end of file diff --git a/modular-recipes/code/recipe/src/lib.rs b/modular-recipes/code/recipe/src/lib.rs new file mode 100644 index 0000000..6203a63 --- /dev/null +++ b/modular-recipes/code/recipe/src/lib.rs @@ -0,0 +1,8 @@ +mod recipe; + +pub use crate::recipe::TomlRecipe; + +#[cfg(test)] +mod tests { + use super::*; +} diff --git a/modular-recipes/code/recipe/src/recipe.rs b/modular-recipes/code/recipe/src/recipe.rs new file mode 100644 index 0000000..9b9ef33 --- /dev/null +++ b/modular-recipes/code/recipe/src/recipe.rs @@ -0,0 +1,64 @@ +use serde::{Deserialize, Serialize}; +use std::fs; +use std::path::Path; + +use std::collections::BTreeMap; + +#[derive(Hash, PartialEq, Eq, Deserialize, Serialize, Debug)] +pub struct Input {} + +#[derive(Hash, PartialEq, Eq, Deserialize, Serialize, Debug)] +pub struct Output {} + +#[derive(Hash, PartialEq, Eq, Deserialize, Serialize, Debug)] +pub struct Dependency {} + +#[derive(Hash, PartialEq, Eq, Deserialize, Serialize, Debug)] +pub struct Config {} + +// Recipe which can get read out of a toml file +#[derive(Deserialize, Serialize, Debug)] +pub struct TomlRecipe { + name: String, + inputs: BTreeMap, + outputs: BTreeMap, + dependencies: BTreeMap, + config: Config, +} + +impl Default for TomlRecipe { + fn default() -> Self { + Self { + name: String::new(), + inputs: BTreeMap::new(), + outputs: BTreeMap::new(), + dependencies: BTreeMap::new(), + config: Config {}, + } + } +} + +impl TomlRecipe { + pub fn new(config_file: &Path) -> Self { + let file: String = fs::read_to_string(&config_file).expect("Could not read input file"); + let recipe: TomlRecipe = toml::from_str(&file).expect("Could not parse TOML file"); + recipe + } + pub fn print(&self) { + println!("{} ---------------", self.name); + println!(" INPUTS"); + for (key, _) in &self.inputs { + println!(" * {}", key); + } + println!(); + println!(" OUTPUTS"); + for (key, _) in &self.outputs { + println!(" * {}", key); + } + println!(); + println!(" DEPENDENCIES"); + for (key, _) in &self.dependencies { + println!(" * {}", key); + } + } +} diff --git a/modular-recipes/code/todo.md b/modular-recipes/code/todo.md new file mode 100644 index 0000000..dd485ae --- /dev/null +++ b/modular-recipes/code/todo.md @@ -0,0 +1,2 @@ +1. recipe visualizer using mermaid or some other charting library +