Skip to content

Commit 0dfff67

Browse files
committed
Add "which" functionality behind feature gate
This patch adds a "which" feature, which uses the "which" crate to check whether the program to call actually exists. The functionality is feature-gated to preserve backwards compatibility. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
1 parent 32d31c9 commit 0dfff67

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,11 @@ regex = "1"
1919
tempfile = "3"
2020
thiserror = "1.0.34"
2121

22+
which = { version = "4.4", optional = true }
23+
2224
[badges]
2325
maintenance = { status = "passively-maintained" }
26+
27+
[features]
28+
default = []
29+
which = ["dep:which"]

src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@ pub enum Error {
3939

4040
#[error("The provided program arguments cannot be parsed")]
4141
BadProgramArguments,
42+
43+
#[cfg(feature = "which")]
44+
#[error(transparent)]
45+
Which(#[from] which::Error),
4246
}

src/session.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ pub fn spawn(program: &str, timeout_ms: Option<u64>) -> Result<PtySession, Error
232232

233233
/// See `spawn`
234234
pub fn spawn_command(command: Command, timeout_ms: Option<u64>) -> Result<PtySession, Error> {
235+
#[cfg(feature = "which")]
236+
{
237+
let _ = which::which(command.get_program())?;
238+
}
235239
let mut process = PtyProcess::new(command)?;
236240
process.set_kill_timeout(timeout_ms);
237241

0 commit comments

Comments
 (0)