-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
54 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use std::env; | ||
use std::path::PathBuf; | ||
|
||
/// Return an absolute path to the provided program (without extension) | ||
/// by checking `PATH` and cycling through `PATHEXT` extensions. | ||
#[cfg(windows)] | ||
pub fn find_command_on_path(name: &str) -> Option<PathBuf> { | ||
let Ok(system_path) = env::var("PATH") else { | ||
return None; | ||
}; | ||
let Ok(path_ext) = env::var("PATHEXT") else { | ||
return None; | ||
}; | ||
let exts = path_ext.split(';').collect::<Vec<_>>(); | ||
|
||
for path_dir in env::split_paths(&system_path) { | ||
for ext in &exts { | ||
let path = path_dir.join(format!("{name}{ext}")); | ||
|
||
if path.exists() { | ||
return Some(path); | ||
} | ||
} | ||
} | ||
|
||
None | ||
} | ||
|
||
/// Return an absolute path to the provided command by checking `PATH`. | ||
#[cfg(not(windows))] | ||
pub fn find_command_on_path(name: &str) -> Option<PathBuf> { | ||
let Ok(system_path) = env::var("PATH") else { | ||
return None; | ||
}; | ||
|
||
for path_dir in env::split_paths(&system_path) { | ||
let path = path_dir.join(name); | ||
|
||
if path.exists() { | ||
return Some(path); | ||
} | ||
} | ||
|
||
None | ||
} | ||
|
||
/// Return true if the provided command/program (without extension) | ||
/// is available on `PATH`. | ||
pub fn is_command_on_path(name: &str) -> bool { | ||
find_command_on_path(name).is_some() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
mod deps; | ||
mod env; | ||
mod error; | ||
mod helpers; | ||
mod pm; | ||
mod pm_vendor; | ||
mod system; | ||
|
||
pub use deps::*; | ||
pub use env::*; | ||
pub use error::*; | ||
pub use helpers::*; | ||
pub use pm::*; | ||
pub use pm_vendor::*; | ||
pub use system::*; |