pub mod change;
pub mod r#move;
pub mod project;
pub mod variable;
use crate::execute::{
task::{Task, ToTask},
Executor,
};
use change::Change;
use project::Project;
use r#move::Move;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use variable::Variable;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Template {
project: Project,
#[serde(default)]
variable: Vec<Variable>,
#[serde(default)]
change: Vec<Change>,
#[serde(default)]
replace: Vec<Move>,
#[serde(skip)]
pub path: PathBuf,
}
impl Template {
pub fn with_path(self, path: PathBuf) -> Self {
Self {
project: self.project,
variable: self.variable,
change: self.change,
replace: self.replace,
path,
}
}
pub fn path(&self) -> &PathBuf {
&self.path
}
pub fn computable(self) -> Executor {
Executor::consume(self)
}
pub fn to_tasks(self) -> Vec<Task> {
let mut tasks: Vec<Task> = Vec::new();
tasks.extend(
self.variable
.iter()
.map(|v| v.to_owned().to_task(&self.path))
.collect::<Vec<Task>>(),
);
tasks.extend(
self.change
.iter()
.map(|v| v.to_owned().to_task(&self.path))
.collect::<Vec<Task>>(),
);
tasks.extend(
self.replace
.iter()
.map(|v| v.to_owned().to_task(&self.path))
.collect::<Vec<Task>>(),
);
tasks.sort();
tasks
}
}