Compare commits
1 Commits
19fdfcdfa5
...
3885d0ba8d
Author | SHA1 | Date | |
---|---|---|---|
3885d0ba8d |
@ -5,7 +5,7 @@ use kdl::KdlDocument;
|
|||||||
use rusty_s3::{Bucket, Credentials, S3Action};
|
use rusty_s3::{Bucket, Credentials, S3Action};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
model::{Context, Plan, Project},
|
model::{Plan, Project},
|
||||||
plan_reconciler::PlanReconciler,
|
plan_reconciler::PlanReconciler,
|
||||||
state::SharedState,
|
state::SharedState,
|
||||||
};
|
};
|
||||||
@ -70,24 +70,16 @@ pub async fn execute() -> anyhow::Result<()> {
|
|||||||
let project: Project = project_doc.try_into()?;
|
let project: Project = project_doc.try_into()?;
|
||||||
tracing::trace!("found a project name: {}", project.name);
|
tracing::trace!("found a project name: {}", project.name);
|
||||||
|
|
||||||
let plan = if let Some(plan_file_path) = PlanReconciler::new()
|
if let Some(plan_file_path) = PlanReconciler::new()
|
||||||
.reconcile(&project, &project_path)
|
.reconcile(&project, &project_path)
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
let plan_file = tokio::fs::read_to_string(&plan_file_path).await?;
|
let plan_file = tokio::fs::read_to_string(&plan_file_path).await?;
|
||||||
let plan_doc: KdlDocument = plan_file.parse()?;
|
let plan_doc: KdlDocument = plan_file.parse()?;
|
||||||
|
|
||||||
let plan: Plan = plan_doc.try_into()?;
|
let project: Plan = plan_doc.try_into()?;
|
||||||
tracing::trace!("found a plan name: {}", project.name);
|
tracing::trace!("found a plan name: {}", project.name);
|
||||||
|
}
|
||||||
Some(plan)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
let context = Context { project, plan };
|
|
||||||
|
|
||||||
tracing::info!("context: {:+?}", context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::Serve {
|
Commands::Serve {
|
||||||
|
@ -1,12 +1,6 @@
|
|||||||
use std::{collections::BTreeMap, fmt::Debug, path::PathBuf};
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use kdl::{KdlDocument, KdlEntry, KdlNode, KdlValue};
|
use kdl::{KdlDocument, KdlNode, KdlValue};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct Context {
|
|
||||||
pub project: Project,
|
|
||||||
pub plan: Option<Plan>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Plan {
|
pub struct Plan {
|
||||||
@ -66,99 +60,11 @@ impl TryFrom<&KdlNode> for ProjectPlan {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub enum GlobalVariable {
|
|
||||||
Map(BTreeMap<String, GlobalVariable>),
|
|
||||||
String(String),
|
|
||||||
Float(f64),
|
|
||||||
Integer(i128),
|
|
||||||
Bool(bool),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<&KdlDocument> for GlobalVariable {
|
|
||||||
type Error = anyhow::Error;
|
|
||||||
|
|
||||||
fn try_from(value: &KdlDocument) -> Result<Self, Self::Error> {
|
|
||||||
let nodes = value.nodes();
|
|
||||||
if nodes.is_empty() {
|
|
||||||
return Ok(Self::Map(BTreeMap::default()));
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut items = BTreeMap::new();
|
|
||||||
for node in nodes {
|
|
||||||
let name = node.name().value();
|
|
||||||
if let Some(children) = node.children() {
|
|
||||||
let val: GlobalVariable = children.try_into()?;
|
|
||||||
items.insert(name.into(), val);
|
|
||||||
} else if let Some(entry) = node.entries().first() {
|
|
||||||
items.insert(name.into(), entry.value().try_into()?);
|
|
||||||
} else {
|
|
||||||
items.insert(name.into(), GlobalVariable::Map(BTreeMap::default()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(GlobalVariable::Map(items))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<&KdlValue> for GlobalVariable {
|
|
||||||
type Error = anyhow::Error;
|
|
||||||
|
|
||||||
fn try_from(value: &KdlValue) -> Result<Self, Self::Error> {
|
|
||||||
if let Some(value) = value.as_string() {
|
|
||||||
return Ok(Self::String(value.to_string()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(value) = value.as_integer() {
|
|
||||||
return Ok(Self::Integer(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(value) = value.as_float() {
|
|
||||||
return Ok(Self::Float(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(value) = value.as_bool() {
|
|
||||||
return Ok(Self::Bool(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
anyhow::bail!("value is not supported by global variables")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
|
||||||
pub struct Global {
|
|
||||||
items: BTreeMap<String, GlobalVariable>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<&KdlNode> for Global {
|
|
||||||
type Error = anyhow::Error;
|
|
||||||
|
|
||||||
fn try_from(value: &KdlNode) -> Result<Self, Self::Error> {
|
|
||||||
let mut global = Global::default();
|
|
||||||
let Some(item) = value.children() else {
|
|
||||||
return Ok(global);
|
|
||||||
};
|
|
||||||
|
|
||||||
for node in item.nodes() {
|
|
||||||
let name = node.name().value();
|
|
||||||
if let Some(children) = node.children() {
|
|
||||||
let val: GlobalVariable = children.try_into()?;
|
|
||||||
global.items.insert(name.into(), val);
|
|
||||||
} else if let Some(entry) = node.entries().first() {
|
|
||||||
global.items.insert(name.into(), entry.value().try_into()?);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(global)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Project {
|
pub struct Project {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub plan: Option<ProjectPlan>,
|
pub plan: Option<ProjectPlan>,
|
||||||
pub global: Global,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<KdlDocument> for Project {
|
impl TryFrom<KdlDocument> for Project {
|
||||||
@ -180,12 +86,6 @@ impl TryFrom<KdlDocument> for Project {
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let global: Option<Global> = if let Some(global) = project_children.get("global") {
|
|
||||||
Some(global.try_into()?)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
name: project_children
|
name: project_children
|
||||||
.get_arg("name")
|
.get_arg("name")
|
||||||
@ -202,7 +102,6 @@ impl TryFrom<KdlDocument> for Project {
|
|||||||
_ => None,
|
_ => None,
|
||||||
}),
|
}),
|
||||||
plan: project_plan,
|
plan: project_plan,
|
||||||
global: global.unwrap_or_default(),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ impl PlanReconciler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tracing::info!("reconciled project");
|
tracing::info!("recociled project");
|
||||||
|
|
||||||
Ok(Some(plan_dir.join("forest.kdl")))
|
Ok(Some(plan_dir.join("forest.kdl")))
|
||||||
}
|
}
|
||||||
|
@ -7,17 +7,4 @@ project {
|
|||||||
plan {
|
plan {
|
||||||
local "../plan"
|
local "../plan"
|
||||||
}
|
}
|
||||||
|
|
||||||
global {
|
|
||||||
someName "name"
|
|
||||||
someKey {
|
|
||||||
someNestedKey "somevalue"
|
|
||||||
some {
|
|
||||||
key {
|
|
||||||
val
|
|
||||||
val
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user