|
|
|
@ -1,5 +1,9 @@
|
|
|
|
|
use config::Config;
|
|
|
|
|
use error::AppResult;
|
|
|
|
|
use scripting::{loader::ScriptLoader, script::Script};
|
|
|
|
|
use scripting::{
|
|
|
|
|
loader::{HookType, ScriptLoader},
|
|
|
|
|
script::{NuScript, Script, ScriptArgs},
|
|
|
|
|
};
|
|
|
|
|
use tasks::*;
|
|
|
|
|
|
|
|
|
|
pub mod config;
|
|
|
|
@ -9,6 +13,7 @@ pub mod tasks;
|
|
|
|
|
pub(crate) mod utils;
|
|
|
|
|
|
|
|
|
|
pub struct TaskExecutor {
|
|
|
|
|
config: Option<Config>,
|
|
|
|
|
loader: ScriptLoader,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -17,7 +22,7 @@ macro_rules! tasks {
|
|
|
|
|
$(
|
|
|
|
|
#[tracing::instrument(level = "trace", skip(self))]
|
|
|
|
|
pub async fn $function(&self, cfg: &<$script as crate::scripting::script::Script>::Args) -> AppResult<()> {
|
|
|
|
|
self.execute::<$script>(cfg).await
|
|
|
|
|
self.execute_task::<$script>(cfg).await
|
|
|
|
|
}
|
|
|
|
|
)+
|
|
|
|
|
}
|
|
|
|
@ -34,9 +39,30 @@ impl TaskExecutor {
|
|
|
|
|
configure_local => ConfigureLocaleScript
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
async fn execute_task<S: Script>(&self, args: &S::Args) -> AppResult<()> {
|
|
|
|
|
if let Some(pre_hook) = self.loader.load_hook::<S>(HookType::Pre) {
|
|
|
|
|
self.execute(pre_hook, args).await?;
|
|
|
|
|
}
|
|
|
|
|
let script = self.loader.load::<S>()?;
|
|
|
|
|
self.execute(script, args).await?;
|
|
|
|
|
|
|
|
|
|
if let Some(post_hook) = self.loader.load_hook::<S>(HookType::Post) {
|
|
|
|
|
self.execute(post_hook, args).await?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
async fn execute<S: Script>(&self, args: &S::Args) -> AppResult<()> {
|
|
|
|
|
self.loader.load::<S>()?.execute(&args).await
|
|
|
|
|
async fn execute<S: Script>(&self, mut script: NuScript<S>, args: &S::Args) -> AppResult<()> {
|
|
|
|
|
if let Some(cfg) = self.config.as_ref() {
|
|
|
|
|
script.set_global_var("TRM_CONFIG", cfg.get_args())
|
|
|
|
|
} else {
|
|
|
|
|
&mut script
|
|
|
|
|
}
|
|
|
|
|
.set_global_var("TRM_VERSION", env!("CARGO_PKG_VERSION"))
|
|
|
|
|
.execute(args)
|
|
|
|
|
.await
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -44,6 +70,7 @@ impl Default for TaskExecutor {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
loader: ScriptLoader::new(),
|
|
|
|
|
config: None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|