93
crates/cuddle/src/actions.rs
Normal file
93
crates/cuddle/src/actions.rs
Normal file
@@ -0,0 +1,93 @@
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use rust_builder::RustActionsBuilder;
|
||||
|
||||
use crate::state::validated_project::Value;
|
||||
|
||||
pub mod builder;
|
||||
|
||||
pub mod rust_builder {
|
||||
use std::path::PathBuf;
|
||||
|
||||
use super::ExecutableActions;
|
||||
|
||||
pub struct RustActionsBuilder {
|
||||
root_path: PathBuf,
|
||||
}
|
||||
|
||||
impl RustActionsBuilder {
|
||||
pub fn new(root_path: PathBuf) -> Self {
|
||||
Self { root_path }
|
||||
}
|
||||
|
||||
pub async fn build(&self) -> anyhow::Result<ExecutableActions> {
|
||||
Ok(ExecutableActions::default())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Actions {
|
||||
variants: Vec<ActionVariant>,
|
||||
}
|
||||
|
||||
impl Actions {
|
||||
pub async fn new(path: &Path, value: &Value) -> anyhow::Result<Option<Self>> {
|
||||
let Some(project) = value.get(&["project", "actions"]) else {
|
||||
tracing::debug!("found no actions folder");
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let mut variants = Vec::default();
|
||||
if let Some(Value::Bool(true)) = project.get(&["rust"]) {
|
||||
tracing::debug!("rust actions enabled");
|
||||
variants.push(ActionVariant::Rust {
|
||||
root_path: path.to_path_buf(),
|
||||
});
|
||||
} else {
|
||||
tracing::trace!("rust actions not enabled");
|
||||
}
|
||||
|
||||
Ok(Some(Self { variants }))
|
||||
}
|
||||
|
||||
pub async fn build(&mut self) -> anyhow::Result<Vec<ExecutableActions>> {
|
||||
let mut executable_actions = Vec::default();
|
||||
|
||||
for variant in &mut self.variants {
|
||||
match variant {
|
||||
ActionVariant::Rust { root_path } => {
|
||||
let actions = RustActionsBuilder::new(root_path.clone()).build().await?;
|
||||
|
||||
executable_actions.push(actions);
|
||||
}
|
||||
ActionVariant::Docker => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(executable_actions)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ActionVariant {
|
||||
Rust { root_path: PathBuf },
|
||||
Docker,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ExecutableActions {
|
||||
actions: Vec<ExecutableAction>,
|
||||
}
|
||||
|
||||
pub struct ExecutableAction {
|
||||
name: String,
|
||||
description: String,
|
||||
flags: BTreeMap<String, ExecutableActionFlag>,
|
||||
}
|
||||
|
||||
pub enum ExecutableActionFlag {
|
||||
String,
|
||||
Bool,
|
||||
}
|
Reference in New Issue
Block a user