45
crates/cuddle/src/state.rs
Normal file
45
crates/cuddle/src/state.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
use crate::{
|
||||
plan::{self, ClonedPlan, PlanPathExt},
|
||||
project::{self, ProjectPlan},
|
||||
schema_validator::SchemaValidator,
|
||||
};
|
||||
|
||||
pub struct State {}
|
||||
impl State {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
pub async fn build_state(
|
||||
&self,
|
||||
project_plan: &ProjectPlan,
|
||||
cloned_plan: &Option<ClonedPlan>,
|
||||
) -> anyhow::Result<RawState> {
|
||||
let project = project::RawProject::from_path(&project_plan.root).await?;
|
||||
let plan = if let Some(_cloned_plan) = cloned_plan {
|
||||
Some(plan::RawPlan::from_path(&project_plan.plan_path()).await?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(RawState { project, plan })
|
||||
}
|
||||
|
||||
pub async fn validate_state(&self, state: &RawState) -> anyhow::Result<ValidatedState> {
|
||||
// 2. Prepare context for actions and components
|
||||
|
||||
if let Some(plan) = &state.plan {
|
||||
SchemaValidator::new().validate(plan, &state.project)?;
|
||||
}
|
||||
|
||||
// 3. Match against schema from plan
|
||||
|
||||
Ok(ValidatedState {})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RawState {
|
||||
project: project::RawProject,
|
||||
plan: Option<plan::RawPlan>,
|
||||
}
|
||||
pub struct ValidatedState {}
|
Reference in New Issue
Block a user