feat: can load workspace members as array

This commit is contained in:
Kasper Juul Hermansen 2025-03-23 20:21:30 +01:00
parent bd927840d6
commit dca625af31
Signed by: kjuulh
SSH Key Fingerprint: SHA256:RjXh0p7U6opxnfd3ga/Y9TCo18FYlHFdSpRIV72S/QM
7 changed files with 57 additions and 6 deletions

View File

@ -78,13 +78,20 @@ pub async fn execute() -> anyhow::Result<()> {
}
let project_file = tokio::fs::read_to_string(&project_file_path).await?;
let project_doc: KdlDocument = project_file.parse()?;
let project: ForestFile = project_doc.try_into()?;
let doc: KdlDocument = project_file.parse()?;
let project: ForestFile = doc.try_into()?;
match project {
ForestFile::Workspace(workspace) => {
tracing::trace!("running as workspace")
tracing::trace!("running as workspace");
// 1. For each member load the project
let output = serde_json::to_string_pretty(&workspace)?;
println!("{}", output.to_colored_json_auto().unwrap_or(output));
// TODO: 1a (optional). Resolve dependencies
// 2. Reconcile plans
// 3. Provide context and aggregated commands for projects
}
ForestFile::Project(project) => {
tracing::trace!("found a project name: {}", project.name);

View File

@ -374,13 +374,57 @@ impl TryFrom<KdlDocument> for Project {
}
#[derive(Debug, Clone, Serialize)]
pub struct Workspace {}
pub struct WorkspaceMember {
pub name: String,
}
impl TryFrom<&kdl::KdlNode> for WorkspaceMember {
type Error = anyhow::Error;
fn try_from(value: &kdl::KdlNode) -> Result<Self, Self::Error> {
Ok(Self {
name: value
.entries()
.first()
.ok_or(anyhow::anyhow!(
"is supposed to have a path `member ./some-path`"
))?
.value()
.as_string()
.ok_or(anyhow::anyhow!("value is required to be a string"))?
.to_string(),
})
}
}
#[derive(Debug, Clone, Serialize)]
pub struct Workspace {
members: Vec<WorkspaceMember>,
}
impl TryFrom<KdlDocument> for Workspace {
type Error = anyhow::Error;
fn try_from(value: KdlDocument) -> Result<Self, Self::Error> {
Ok(Self {})
let workspace = value
.get("workspace")
.expect("to have a workspace at this point")
.children()
.ok_or(anyhow::anyhow!("workspace to be a section"))?;
Ok(Self {
members: workspace
.get("members")
.ok_or(anyhow::anyhow!(
"a members section is required for a workspace"
))?
.children()
.ok_or(anyhow::anyhow!("a members is required to have children"))?
.nodes()
.iter()
.map(|m| m.try_into())
.collect::<anyhow::Result<Vec<_>>>()?,
})
}
}

View File

View File

View File

View File