diff --git a/src/config.rs b/src/config.rs index 0b1c2ee..be7326a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -74,6 +74,8 @@ pub struct Plugin { pub hook_type: HookType, pub name: String, pub hash: String, + #[serde(flatten)] + pub args: HashMap, } impl Plugin { @@ -86,6 +88,16 @@ impl Plugin { Ok(digest.to_string()) } + pub fn get_args(&self) -> Vec { + let mut args = Vec::new(); + + for arg in &self.args { + args.push(format!("{}={}", arg.0, arg.1)); + } + + args + } + pub fn resolve(&self, plugin_dir: &Path, no_verify: bool) -> Result { let mut plugin_path = PathBuf::from(plugin_dir); plugin_path.push(&self.name); @@ -114,9 +126,13 @@ impl Plugin { } pub fn run(&self, config: &Config, root_dir: &Path, no_verify: bool) -> Result<()> { + println!("Running plugin {}...", &self.name); + let plugin_file = self.resolve(Path::new(&config.build.plugin_dir), no_verify)?; + let args = self.get_args(); let status = std::process::Command::new(&plugin_file) + .args(args) .current_dir(root_dir) .status()?; let code = status diff --git a/src/main.rs b/src/main.rs index b6a094c..3986f0a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use anyhow::{Result, anyhow}; -use std::{path::Path, process::exit, sync::Arc}; +use std::{collections::HashMap, path::Path, process::exit, sync::Arc}; use crate::{ args::{DEFAULT_TARS_CONFIG_FILE, InitArgs, PluginSubcommand, TarsSubcommand, parse_args}, @@ -129,6 +129,7 @@ async fn main() { name: args.name, hook_type: HookType::Pre, hash: "".to_string(), + args: HashMap::new(), }; match plugin.get_hash(Path::new(&args.plugin_dir)) {