Add support for multiple binary names and idea having multiple binaries (#1167)
Add support for tools to have multiple possible binaries because IntellIj IDEA on the AUR can have multiple depending on the edition. [AUR Ultimate Edition](https://aur.archlinux.org/packages/intellij-idea-ultimate-edition) and [AUR Community Edition](https://aur.archlinux.org/packages/intellij-idea-community-edition-bin) renames the binary to `intellij-idea-ultimate-edition` and `intellij-idea-community-edition` respectively.
This commit is contained in:
23
src/utils.rs
23
src/utils.rs
@@ -112,6 +112,29 @@ pub fn require<T: AsRef<OsStr> + Debug>(binary_name: T) -> Result<PathBuf> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn require_one<T: AsRef<OsStr> + Debug>(binary_names: impl IntoIterator<Item = T>) -> Result<PathBuf> {
|
||||
let mut failed_bins = Vec::new();
|
||||
for bin in binary_names {
|
||||
match require(&bin) {
|
||||
Ok(path) => return Ok(path),
|
||||
Err(_) => failed_bins.push(bin),
|
||||
}
|
||||
}
|
||||
|
||||
Err(SkipStep(format!(
|
||||
"{}",
|
||||
t!(
|
||||
"Cannot find any of {binary_names} in PATH",
|
||||
binary_names = failed_bins
|
||||
.iter()
|
||||
.map(|bin| format!("{:?}", bin))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
)
|
||||
))
|
||||
.into())
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn require_option<T>(option: Option<T>, cause: String) -> Result<T> {
|
||||
if let Some(value) = option {
|
||||
|
||||
Reference in New Issue
Block a user