use plan::{ClonedPlan, Plan}; use project::ProjectPlan; use state::ValidatedState; mod plan; mod project; mod schema_validator; mod state; #[tokio::main] async fn main() -> anyhow::Result<()> { dotenv::dotenv().ok(); tracing_subscriber::fmt::init(); let _cuddle = Cuddle::default() .prepare_project() .await? .prepare_plan() .await? .build_state() .await?; Ok(()) } struct Start {} struct PrepareProject { project: Option, } struct PreparePlan { project: Option, plan: Option, } struct Cuddle { state: S, } // Cuddle maintains the context for cuddle to use // Stage 1 figure out which state to display // Stage 2 prepare plan // Stage 3 validate settings, build actions, prepare impl Cuddle {} impl Cuddle { pub fn default() -> Self { Self { state: Start {} } } pub async fn prepare_project(&self) -> anyhow::Result> { let project = ProjectPlan::from_current_path().await?; Ok(Cuddle { state: PrepareProject { project }, }) } } impl Cuddle { pub async fn prepare_plan(&self) -> anyhow::Result> { let plan = if let Some(project) = &self.state.project { Plan::new().clone_from_project(project).await? } else { None }; Ok(Cuddle { state: PreparePlan { project: self.state.project.clone(), plan, }, }) } } impl Cuddle { pub async fn build_state(&self) -> anyhow::Result> { let state = if let Some(project) = &self.state.project { let state = state::State::new(); let raw_state = state.build_state(project, &self.state.plan).await?; state.validate_state(&raw_state).await? } else { ValidatedState::default() }; Ok(Cuddle { state }) } }