use super::{PluginConfig, PluginMode};
use crate::config::ServerAddr;
use std::{net::SocketAddr, process::Stdio};
use tokio::process::Command;
pub fn plugin_cmd(plugin: &PluginConfig, remote: &ServerAddr, local: &SocketAddr, mode: PluginMode) -> Command {
let mut cmd = Command::new(&plugin.plugin);
cmd.stdin(Stdio::null())
.kill_on_drop(true)
.arg("--data-dir")
.arg(format!("/tmp/{}_{}_{}", plugin.plugin, remote, local));
if let Some(ref opt) = plugin.plugin_opts {
cmd.args(opt.split(' '));
}
match mode {
PluginMode::Client => cmd
.arg("--dest")
.arg(remote.to_string())
.arg("client")
.arg(local.to_string()),
PluginMode::Server => cmd
.arg("--dest")
.arg(local.to_string())
.arg("server")
.arg(remote.to_string()),
};
if !plugin.plugin_args.is_empty() {
cmd.args(&plugin.plugin_args);
}
cmd
}