diff --git a/src/plugins/cmd/mod.rs b/src/plugins/cmd/mod.rs index 867fa56..f15f6a6 100644 --- a/src/plugins/cmd/mod.rs +++ b/src/plugins/cmd/mod.rs @@ -20,17 +20,20 @@ fn register() { #[derive(Clone)] pub(crate) struct Command { opts: options::Options, + binary: String, } impl Command { pub fn new() -> Self { Command { opts: options::Options::default(), + binary: String::default(), } } async fn run(&self, creds: &Credentials) -> Result { let (target, port) = utils::parse_target(&creds.target, 0)?; + let args = shell_words::split( &self .opts @@ -42,13 +45,13 @@ impl Command { ) .unwrap(); - log::debug!("{} {}", &self.opts.cmd_binary, args.join(" ")); + log::debug!("{} {}", &self.binary, args.join(" ")); - let child = std::process::Command::new(&self.opts.cmd_binary) + let child = std::process::Command::new(&self.binary) .args(&args) .stdin(Stdio::null()) - .stdout(Stdio::null()) - .stderr(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) .spawn() .map_err(|e| e.to_string())?; @@ -63,12 +66,9 @@ impl Plugin for Command { } fn setup(&mut self, opts: &Options) -> Result<(), Error> { + self.binary = opts.target.clone().unwrap(); self.opts = opts.cmd.clone(); - if self.opts.cmd_binary.is_empty() { - Err("please provide --cmd-binary and optionally --cmd-args".to_owned()) - } else { - Ok(()) - } + Ok(()) } async fn attempt(&self, creds: &Credentials, timeout: Duration) -> Result, Error> { diff --git a/src/plugins/cmd/options.rs b/src/plugins/cmd/options.rs index 0f499b1..f9e41a8 100644 --- a/src/plugins/cmd/options.rs +++ b/src/plugins/cmd/options.rs @@ -4,10 +4,6 @@ use serde::{Deserialize, Serialize}; #[derive(Parser, Debug, Serialize, Deserialize, Clone, Default)] #[group(skip)] pub(crate) struct Options { - #[clap(long, default_value = "")] - /// Command binary path. - pub cmd_binary: String, - #[clap(long, default_value = "")] /// Command arguments. {USERNAME}, {PASSWORD}, {TARGET} and {PORT} can be used as placeholders. pub cmd_args: String,