feat: expose the plan model from the reconciler

This commit is contained in:
2025-02-13 23:14:17 +01:00
parent b629bcf924
commit c1bbf6a69e
3 changed files with 54 additions and 9 deletions

View File

@@ -2,6 +2,36 @@ use std::path::PathBuf;
use kdl::{KdlDocument, KdlNode, KdlValue};
#[derive(Debug, Clone)]
pub struct Plan {
pub name: String,
}
impl TryFrom<KdlDocument> for Plan {
type Error = anyhow::Error;
fn try_from(value: KdlDocument) -> Result<Self, Self::Error> {
let plan_section = value.get("plan").ok_or(anyhow::anyhow!(
"forest.kdl plan file must have a plan object"
))?;
let plan_children = plan_section
.children()
.ok_or(anyhow::anyhow!("a forest plan must have children"))?;
Ok(Self {
name: plan_children
.get_arg("name")
.and_then(|n| match n {
KdlValue::String(s) => Some(s),
_ => None,
})
.cloned()
.ok_or(anyhow::anyhow!("a forest kuddle plan must have a name"))?,
})
}
}
#[derive(Debug, Clone)]
pub enum ProjectPlan {
Local { path: PathBuf },