diff --git a/tools/src/bin/parser/main.rs b/tools/src/bin/parser/main.rs index 3b29a83..dda1452 100644 --- a/tools/src/bin/parser/main.rs +++ b/tools/src/bin/parser/main.rs @@ -1,79 +1,28 @@ use clap::Parser; +use tools::Recipe; +use tools::Repo; + #[derive(Debug, clap::Parser)] #[command(version, about, long_about = None)] struct Args { + // The name of the recipe to build. target: String, -} -// #[derive(Debug, serde::Deserialize)] -// enum Quantity { -// Count(usize), -// Amount(String), -// } - -#[derive(Debug, serde::Deserialize)] -struct Input { - /// Each input has either a `quantity` (for discrete things, like - /// apples or bearings) or an `amount` (for continuous things, - /// like rope or flour). - /// - /// FIXME: Is there a good way to handle the "units" of the - /// quantity/amount? Maybe the units could default to "count", but - /// be optionally overridden by the recipe to things like "meters" - /// (of tubing) or "grams" (of chromic acid). Then this struct - /// would be `quantity: usize, units: Option`. - quantity: Option, - amount: Option, -} - -#[derive(Debug, serde::Deserialize)] -struct Operator { - skills: Vec, -} - -#[derive(Debug, serde::Deserialize)] -struct Dependencies { - tools: Vec, - operator: Operator, -} - -#[derive(Debug, serde::Deserialize)] -struct Action { - process: String, -} - -#[derive(Debug, serde::Deserialize)] -struct Recipe { - /// `[inputs]` is a Table where each key the the name (unique id) - /// of a recipe in the repo, and the value is an Input object. - inputs: std::collections::HashMap, - - dependencies: Dependencies, - action: Action, - - /// If a recipe has no `[outputs]`, we assume it produces 1x of the - /// thing identified by the name of the recipe. - /// - /// FIXME: Or is that always the case, and we should have no outputs - /// section? None of the recipes we've been doodling around with - /// have anything like byproducts or waste streams... - outputs: Option>, -} - -fn validate_recipe(recipe: &Recipe) -> anyhow::Result<()> { - // if recipe.inputs.len() == 0 { - // Err("recipe has no inputs!"); - // } - Ok(()) + /// Directory containing the repo of all repositories. + #[arg(short, long)] + repo: String, } fn main() -> anyhow::Result<()> { let args = Args::parse(); + + let repo_contents = std::fs::read_dir(args.repo).unwrap(); + let target_str = std::fs::read_to_string(args.target)?; let recipe: Recipe = toml::from_str(&target_str)?; println!("{recipe:#?}"); - let r = validate_recipe(&recipe); + let r = tools::recipe::validate_recipe(&recipe); println!("valid? {r:#?}"); Ok(()) } diff --git a/tools/src/lib.rs b/tools/src/lib.rs new file mode 100644 index 0000000..fbe3eac --- /dev/null +++ b/tools/src/lib.rs @@ -0,0 +1,5 @@ +pub mod recipe; +pub use recipe::Recipe; + +pub mod repo; +pub use repo::Repo; diff --git a/tools/src/recipe.rs b/tools/src/recipe.rs new file mode 100644 index 0000000..480615a --- /dev/null +++ b/tools/src/recipe.rs @@ -0,0 +1,62 @@ +// #[derive(Debug, serde::Deserialize)] +// enum Quantity { +// Count(usize), +// Amount(String), +// } + +#[derive(Debug, serde::Deserialize)] +pub struct Input { + /// Each input has either a `quantity` (for discrete things, like + /// apples or bearings) or an `amount` (for continuous things, + /// like rope or flour). + /// + /// FIXME: Is there a good way to handle the "units" of the + /// quantity/amount? Maybe the units could default to "count", but + /// be optionally overridden by the recipe to things like "meters" + /// (of tubing) or "grams" (of chromic acid). Then this struct + /// would be `quantity: usize, units: Option`. + quantity: Option, + amount: Option, +} + +#[derive(Debug, serde::Deserialize)] +pub struct Operator { + skills: Vec, +} + +#[derive(Debug, serde::Deserialize)] +pub struct Dependencies { + tools: Vec, + operator: Operator, +} + +#[derive(Debug, serde::Deserialize)] +pub struct Action { + process: String, +} + +#[derive(Debug, serde::Deserialize)] +pub struct Recipe { + /// `[inputs]` is a Table where each key the the name (unique id) + /// of a recipe in the repo, and the value is an Input object. + inputs: std::collections::HashMap, + + dependencies: Dependencies, + + action: Action, + + /// If a recipe has no `[outputs]`, we assume it produces 1x of the + /// thing identified by the name of the recipe. + /// + /// FIXME: Or is that always the case, and we should have no outputs + /// section? None of the recipes we've been doodling around with + /// have anything like byproducts or waste streams... + outputs: Option>, +} + +pub fn validate_recipe(recipe: &Recipe) -> anyhow::Result<()> { + // if recipe.inputs.len() == 0 { + // Err("recipe has no inputs!"); + // } + Ok(()) +} diff --git a/tools/src/repo.rs b/tools/src/repo.rs new file mode 100644 index 0000000..3e966a8 --- /dev/null +++ b/tools/src/repo.rs @@ -0,0 +1,6 @@ +use crate::recipe::Recipe; + +pub struct Repo { + path: String, + recipes: std::collections::HashMap, +}