1use std::ffi::OsString;
9use std::process::Command;
10
11use ready_set_sdk::ExitCode;
12
13use crate::discovery::PluginEntry;
14use crate::env::{EnvContract, export_contract};
15
16#[cfg(unix)]
20pub fn dispatch_to_plugin(
21 entry: &PluginEntry,
22 args: &[OsString],
23 contract: &EnvContract,
24) -> ExitCode {
25 use std::os::unix::process::CommandExt;
26
27 let mut cmd = Command::new(&entry.binary_path);
28 cmd.args(args);
29 export_contract(&mut cmd, contract);
30 let err = cmd.exec();
31 eprintln!(
33 "ready-set: failed to exec {}: {err}",
34 entry.binary_path.display()
35 );
36 ExitCode::SystemError
37}
38
39#[cfg(windows)]
43pub fn dispatch_to_plugin(
44 entry: &PluginEntry,
45 args: &[OsString],
46 contract: &EnvContract,
47) -> ExitCode {
48 let mut cmd = Command::new(&entry.binary_path);
49 cmd.args(args);
50 export_contract(&mut cmd, contract);
51 match cmd.status() {
52 Ok(status) => match status.code() {
53 Some(0) => ExitCode::Ok,
54 Some(127) => ExitCode::UnknownSubcommand,
55 Some(_) | None => ExitCode::SystemError,
56 },
57 Err(err) => {
58 eprintln!(
59 "ready-set: failed to spawn {}: {err}",
60 entry.binary_path.display()
61 );
62 ExitCode::SystemError
63 },
64 }
65}