Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ pub struct Plugin {
pub hook_type: HookType,
pub name: String,
pub hash: String,
#[serde(flatten)]
pub args: HashMap<String, toml::Value>,
}

impl Plugin {
Expand All @@ -86,6 +88,16 @@ impl Plugin {
Ok(digest.to_string())
}

pub fn get_args(&self) -> Vec<String> {
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<PathBuf> {
let mut plugin_path = PathBuf::from(plugin_dir);
plugin_path.push(&self.name);
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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)) {
Expand Down