feat: can load workspace members as array
This commit is contained in:
parent
bd927840d6
commit
dca625af31
@ -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);
|
||||
|
@ -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<_>>>()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
0
examples/workspace/components/flux/forest.kdl
Normal file
0
examples/workspace/components/flux/forest.kdl
Normal file
0
examples/workspace/plan/a/forest.kdl
Normal file
0
examples/workspace/plan/a/forest.kdl
Normal file
0
examples/workspace/plan/b/forest.kdl
Normal file
0
examples/workspace/plan/b/forest.kdl
Normal file
0
examples/workspace/projects/a/forest.kdl
Normal file
0
examples/workspace/projects/a/forest.kdl
Normal file
0
examples/workspace/projects/b/forest.kdl
Normal file
0
examples/workspace/projects/b/forest.kdl
Normal file
Loading…
x
Reference in New Issue
Block a user