mod invocation;
mod path_selection;
mod process;
mod validation;
#[cfg(windows)]
mod windows;
pub(crate) use invocation::resolve_command_invocation;
use process::run_os_command;
use crate::{SubprocessError, SubprocessOutput, SubprocessRuntime};
#[cfg(test)]
pub(crate) use path_selection::{candidate_priority, select_path_candidate};
#[cfg(all(windows, test))]
pub(crate) use path_selection::candidate_priority as windows_program_priority;
#[cfg(all(windows, test))]
pub(crate) use windows::{resolve_cmd_exe, windows_quote_for_cmd};
#[cfg(windows)]
pub(super) fn resolve_windows_program_pub(program: &str) -> Option<String> {
windows::resolve_windows_program(program)
}
pub struct OsSubprocessRuntime {
timeout_secs: Option<u64>,
}
impl OsSubprocessRuntime {
pub fn new() -> Self {
Self { timeout_secs: None }
}
pub fn with_timeout(timeout_secs: u64) -> Self {
assert!(timeout_secs > 0, "timeout_secs must be greater than zero");
Self { timeout_secs: Some(timeout_secs) }
}
}
impl Default for OsSubprocessRuntime {
fn default() -> Self {
Self::new()
}
}
impl SubprocessRuntime for OsSubprocessRuntime {
fn run_command(
&self,
program: &str,
args: &[&str],
stdin: Option<&[u8]>,
) -> Result<SubprocessOutput, SubprocessError> {
run_os_command(program, args, stdin, self.timeout_secs)
}
}