WIP: start parsing recipes

This commit is contained in:
Sebastian Kuzminsky 2025-01-12 23:35:13 -07:00
parent 86bd75b63e
commit aca1e0715f
3 changed files with 416 additions and 0 deletions

60
tools/src/main.rs Normal file
View file

@ -0,0 +1,60 @@
use clap::Parser;
#[derive(Debug, clap::Parser)]
#[command(version, about, long_about = None)]
struct Args {
target: String,
}
// #[derive(Debug, serde::Deserialize)]
// enum Quantity {
// Count(usize),
// Amount(String),
// }
#[derive(Debug, serde::Deserialize)]
struct Input {
quantity: Option<usize>,
amount: Option<String>,
}
#[derive(Debug, serde::Deserialize)]
struct Operator {
skills: Vec<String>,
}
#[derive(Debug, serde::Deserialize)]
struct Dependencies {
tools: Vec<String>,
operator: Operator,
}
#[derive(Debug, serde::Deserialize)]
struct Action {
process: String,
}
#[derive(Debug, serde::Deserialize)]
struct Recipe {
inputs: std::collections::HashMap<String, Input>,
dependencies: Dependencies,
action: Action,
outputs: Option<Vec<String>>,
}
fn validate_recipe(recipe: &Recipe) -> anyhow::Result<()> {
// if recipe.inputs.len() == 0 {
// Err("recipe has no inputs!");
// }
Ok(())
}
fn main() -> anyhow::Result<()> {
let args = Args::parse();
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);
println!("valid? {r:#?}");
Ok(())
}