pub fn command_exists(cmd: &str) -> boolExpand description
Checks if a command is available in the system PATH.
This function searches the system PATH for the specified command and returns whether it can be found and is executable. This is useful for verifying that required external tools (like Git) are available before attempting to use them.
§Arguments
cmd- The command name to search for
§Returns
true if the command exists and is executable, false otherwise
§Examples
use agpm_cli::utils::platform::command_exists;
// Check if Git is available
if command_exists("git") {
println!("Git is available");
} else {
eprintln!("Git is not installed or not in PATH");
}
// Platform-specific commands
#[cfg(windows)]
let shell_available = command_exists("cmd");
#[cfg(unix)]
let shell_available = command_exists("sh");§Platform Behavior
- Windows: Searches PATH and PATHEXT for executable files
- Unix-like: Searches PATH for executable files
- All platforms: Respects system PATH configuration
§Use Cases
- Validating tool availability before execution
- Providing helpful error messages when tools are missing
- Feature detection based on available commands
- System requirements checking
§Performance
This function performs filesystem operations and may be relatively slow. Consider caching results if checking the same command multiple times.
§See Also
get_git_commandfor getting the platform-appropriate Git command name