use std::ffi::OsString;
use std::process::Command;
use ready_set_sdk::ExitCode;
use crate::discovery::PluginEntry;
use crate::env::{EnvContract, export_contract};
#[cfg(unix)]
pub fn dispatch_to_plugin(
entry: &PluginEntry,
args: &[OsString],
contract: &EnvContract,
) -> ExitCode {
use std::os::unix::process::CommandExt;
let mut cmd = Command::new(&entry.binary_path);
cmd.args(args);
export_contract(&mut cmd, contract);
let err = cmd.exec();
eprintln!(
"ready-set: failed to exec {}: {err}",
entry.binary_path.display()
);
ExitCode::SystemError
}
#[cfg(windows)]
pub fn dispatch_to_plugin(
entry: &PluginEntry,
args: &[OsString],
contract: &EnvContract,
) -> ExitCode {
let mut cmd = Command::new(&entry.binary_path);
cmd.args(args);
export_contract(&mut cmd, contract);
match cmd.status() {
Ok(status) => match status.code() {
Some(0) => ExitCode::Ok,
Some(127) => ExitCode::UnknownSubcommand,
Some(_) | None => ExitCode::SystemError,
},
Err(err) => {
eprintln!(
"ready-set: failed to spawn {}: {err}",
entry.binary_path.display()
);
ExitCode::SystemError
},
}
}