2024-08-24 14:55:26 +02:00
|
|
|
use plan::{ClonedPlan, Plan};
|
2024-08-24 00:45:16 +02:00
|
|
|
use project::ProjectPlan;
|
2024-08-24 14:55:26 +02:00
|
|
|
use state::ValidatedState;
|
2024-08-23 23:22:35 +02:00
|
|
|
|
2024-08-24 00:45:16 +02:00
|
|
|
mod plan;
|
|
|
|
mod project;
|
2024-08-24 14:55:26 +02:00
|
|
|
mod schema_validator;
|
|
|
|
mod state;
|
2024-08-23 21:51:42 +02:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> anyhow::Result<()> {
|
|
|
|
dotenv::dotenv().ok();
|
|
|
|
tracing_subscriber::fmt::init();
|
|
|
|
|
2024-08-24 00:45:16 +02:00
|
|
|
let _cuddle = Cuddle::default()
|
|
|
|
.prepare_project()
|
|
|
|
.await?
|
|
|
|
.prepare_plan()
|
2024-08-24 14:55:26 +02:00
|
|
|
.await?
|
|
|
|
.build_state()
|
2024-08-24 00:45:16 +02:00
|
|
|
.await?;
|
2024-08-23 23:21:53 +02:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2024-08-24 00:45:16 +02:00
|
|
|
struct Start {}
|
|
|
|
struct PrepareProject {
|
|
|
|
project: Option<ProjectPlan>,
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PreparePlan {
|
|
|
|
project: Option<ProjectPlan>,
|
2024-08-24 14:55:26 +02:00
|
|
|
plan: Option<ClonedPlan>,
|
2024-08-24 00:45:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Cuddle<S = Start> {
|
|
|
|
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<Start> {
|
|
|
|
pub fn default() -> Self {
|
|
|
|
Self { state: Start {} }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn prepare_project(&self) -> anyhow::Result<Cuddle<PrepareProject>> {
|
|
|
|
let project = ProjectPlan::from_current_path().await?;
|
|
|
|
|
|
|
|
Ok(Cuddle {
|
|
|
|
state: PrepareProject { project },
|
|
|
|
})
|
|
|
|
}
|
2024-08-23 23:21:53 +02:00
|
|
|
}
|
|
|
|
|
2024-08-24 00:45:16 +02:00
|
|
|
impl Cuddle<PrepareProject> {
|
|
|
|
pub async fn prepare_plan(&self) -> anyhow::Result<Cuddle<PreparePlan>> {
|
2024-08-24 14:55:26 +02:00
|
|
|
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<PreparePlan> {
|
|
|
|
pub async fn build_state(&self) -> anyhow::Result<Cuddle<ValidatedState>> {
|
|
|
|
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 {}
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(Cuddle { state })
|
2024-08-23 21:51:42 +02:00
|
|
|
}
|
2024-08-23 23:21:53 +02:00
|
|
|
}
|