espforge_lib/parse/
project.rs1use crate::parse::EspforgeConfiguration;
2use crate::parse::processor::{ProcessorRegistration, SectionProcessor};
3use anyhow::{Context, Result};
4use serde::Deserialize;
5use serde_yaml_ng::Value;
6
7#[derive(Deserialize)]
8struct ProjectConfig {
9 name: String,
10 chip: Option<String>,
11 platform: Option<String>,
12}
13
14pub struct ProjectInfoProvisioner;
15
16impl SectionProcessor for ProjectInfoProvisioner {
17 fn section_key(&self) -> &'static str {
18 "espforge"
19 }
20
21 fn priority(&self) -> u32 {
22 1000
23 }
24
25 fn process(&self, content: &Value, model: &mut EspforgeConfiguration) -> Result<()> {
26 let config: ProjectConfig = serde_yaml_ng::from_value(content.clone())
27 .context("Failed to deserialize espforge configuration")?;
28
29 model.name = config.name;
30
31 if let Some(chip) = config.chip {
32 model.chip = chip;
33 } else if let Some(platform) = config.platform {
34 model.chip = platform;
35 }
36
37 println!("✓ Project metadata provisioned");
38
39 Ok(())
40 }
41}
42
43inventory::submit! {
44 ProcessorRegistration {
45 factory: || Box::new(ProjectInfoProvisioner),
46 }
47}